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}
 }
};
 
What is the name of the NuGet package?

In general it should not matter if a class is declared from a NuGet package or if you declare it yourself.

As an aside, why are you using a very old NuGet package targeting an obsolete framework version, but obviously using a much more modern C# syntax? Hopefully your compiler is a modern version.
 
What is the name of the NuGet package?

In general it should not matter if a class is declared from a NuGet package or if you declare it yourself.

As an aside, why are you using a very old NuGet package targeting an obsolete framework version, but obviously using a much more modern C# syntax? Hopefully your compiler is a modern version.
Thank you for your reply
I installed the offline package.
one question:
To use this syntax, what version of .netframework and Visual Studio should I use?
 
I installed the offline package.

I repeat the question: what is the name of NuGet package so that we can see for ourselves if we can reproduce your problem?
 
Unforunately, that link seems to use www.intamedia.ir that doesn't seem to be up right now.

Why didn't you just say that you are using the "TaxCollectData.Library" Nuget package?
 
I don't know. That package wouldn't even download from that link you provided.

As for the version on NuGet. It seems to be compatible with 4.8. I have some doubts about it being compatible with 4.6. You will have to research if NET Standard 2.0 is compatible with that old a version.

Also recalled that 4.6 is way past end of life. The oldest supported version of .Net Framework is 4.6.2.
 
Still failing to download:
1685290711724.png
 
Perhaps it's not available to non Iranian IP addresses. @resident if you can access it why not just upload it to the forum? Give us everything we need to help you; it's the most courteous thing to do for someone who offers you help for free
 
erhaps it's not available to non Iranian IP addresses. @resident if you can access it why not just upload it to the forum? Give us everything we need to help you; it's the most courteous thing to do for someone who offers you help for free

Ok. I will do it in full in a separate post
 
Back
Top Bottom