Open RealDotNetDave opened 3 months ago
XmlElementAttribute is marked as the following:
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.ReturnValue, AllowMultiple=true)]
public class XmlElementAttribute : Attribute
That AllowMultiple=true
on the attribute means that multiple of these attributes can be applied. If it was marked as AllowMultiple=false
then this would error.
Version Used: I am using Visual Studio 2022 v17.10.3 with .NET 8.
I have found an issue with XML deserialization of a type that took me a few days to figure out. This is the error I was getting:
I discovered that the issue was due to duplicate XML attributes being added to the property, which I might have overlooked while using Copilot. Below is the code for the property that caused the exception:
Once I removed the [XmlElement], everything worked as expected. The compiler should have verified that there were no duplicate serialization attributes and produced an error if it detected any. This issue was discovered while I was benchmarking the code. You can find this on the Spargine repository at this URL: https://github.com/RealDotNetDave/dotNetTips.Spargine.8/blob/master/source/dotNetTips.Spargine.8.Tester/Models/RefTypes/Address.cs