0

I am building an XML file and when add this part of AllowanceCharge it gives me this error Name of field or property being initialized in an object initializer must start with '.'. and all the names start with period! what could be the issue here?

My code is:

         .AllowanceCharge = New List(Of AllowanceChargeType) From
                {
                    New AllowanceChargeType With
                    {
                        .ChargeIndicator = False,
                        .AllowanceChargeReason = New List(Of TextType) From
                        {
                            New TextType With
                            {
                                .Value = "discount"
                            }
                        },
                        .Amount = New AmountType With
                        {
                            .currencyID = "SAR",
                            .Value = 100
                        },
                        .TaxCategory = New TaxCategoryType With {
                            .ID = New IdentifierType With {
                            .Value = "S"
                            },
                            .Percent = 15.0,
                            .TaxScheme = New TaxSchemeType With {
                            .ID = "VAT"
                            },
                        }
                    }
                },

The issue come when I added this part:

                        .TaxCategory = New TaxCategoryType With {
                           .ID = New IdentifierType With {
                           .Value = "S"
                           },
                           .Percent = 20,
                           .TaxScheme = New TaxSchemeType With {
                           .ID = "VAT"
                            },
                        }
MK Said
  • 165
  • 8
  • 1
    Your code is quite complex. When you have issues that you can't work out with complex code, you should strip it back to the simplest case you can, then build it up in simple steps until it breaks. You then know that the issue is with the last bit you added. Also, that's obviously not all the relevant code. After doing as I said to try to fix it yourself, please provide [a minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – jmcilhinney Jan 06 '23 at 09:48
  • The issue come when add `.TaxCategory` – MK Said Jan 06 '23 at 09:53
  • I'd strongly recommend for you to ensure that you have consistent indentation with your braces. It looks like for what you have posted, you might have unmatched braces, which could lead the VB compiler to get confused and think that a following line is part of the initializer. I'm not sure if the potential mismatch is real or just an artifact of your posting the problem to SO. – Craig Jan 06 '23 at 16:33

0 Answers0