Error in Initializing the class : Member 'P1' cannot be initialized. It is not a field or property

resident

Active member
Joined
May 8, 2023
Messages
25
Programming Experience
5-10
I installed a nugget package (targeting the framework 4.6.1) and using it I want to send some invoices.

The class defined for the invoice (installed from nugget):
C#:
[NullableAttribute(0)]
[NullableContextAttribute(1)]
public class InvoiceDao : IEquatable<InvoiceDao>
{
        public InvoiceDao();
        [CompilerGenerated]
        protected InvoiceDao(InvoiceDao original);

        public List<InvoiceItemDao> Items { get; set; }

        [CompilerGenerated]
        public List<InvoiceItemDao> get_Item();
}

Each invoice contains a number of items for which a separate class is defined (installed from nugget):

C#:
[NullableAttribute(0)]
[NullableContextAttribute(1)]
public class InvoiceItemDao
{
            public InvoiceItemDao();
   
            public decimal P1 { get; set; }
            public string P2 { get; set; }
            .
            .
            .
            [CompilerGenerated]
            public decimal get_P1();
            [CompilerGenerated]
            public string get_P2();
}

The problem I have is how to give the values of the invoice and its items to the SendInvoices function?


C#:
InvoiceDao invoiceDao = new InvoiceDao();
var invoices = new List<InvoiceDao>
{
     //how to initialize invoiceDao ??
};

SendInvoices(invoices, null);

When I try to set the value in the following way, it gives this error:

Member 'P1' cannot be initialized. It is not a field or property.
Member 'P2' cannot be initialized. It is not a field or property.


C#:
var Item= new InvoiceItemDao
{
 P1= "110",
 P2="Name"
};

var invoices = new List<InvoiceDao>
{
 new()
 {
    Items= new() {Item}
 }
};
 
Back
Top Bottom