Token StartAttribute in state Element Content would result in an invalid XML document.
See original GitHub issueWhen an element contains both an attribute and an element the exception Token StartAttribute in state Element Content would result in an invalid XML document.
is thrown. This seems to have something to do with EnableMemberExceptionHandling()
.
For this sample I have the following classes:
public class RootElement
{
public Bar Bar { get; set; }
public string Version { get; set; }
}
public class Bar
{
public string Name { get; set; }
}
Tests
Test 1
- Without
EnableMemberExceptionHandling()
RootElement
has an attribute namedVersion
, which is set.RootElement
has an elementBar
, which is set.
var c = new ConfigurationContainer()
.ConfigureType<RootElement>()
.Name("Root")
.Member(re => re.Version)
.Attribute()
.ConfigureType<Bar>()
.Create();
var r = new RootElement
{
Version = "1",
Bar = new Bar { Name = "bar" },
};
r.SerializeToFile();
c.Cycle(r).Should().BeEquivalentTo(r);
This gives the following result:
<?xml version="1.0" encoding="utf-8"?>
<Root UniformsVersion="1" xmlns="clr-namespace:Unittests.Serialization;assembly=Unittests">
<Bar>
<Name>bar</Name>
</Bar>
</Root>
Test 2
- With
EnableMemberExceptionHandling()
RootElement
has an attribute namedVersion
, which is set.RootElement
has an elementBar
, which is set.
var c = new ConfigurationContainer()
.EnableMemberExceptionHandling()
.ConfigureType<RootElement>()
.Name("Root")
.Member(re => re.Version)
.Attribute()
.ConfigureType<Bar>()
.Create();
var r = new RootElement
{
Version = "1",
Bar = new Bar { Name = "bar" },
};
r.SerializeToFile();
c.Cycle(r).Should().BeEquivalentTo(r);
Which throws the following stacktrace:
Test Name: Unittests.Serialization.SerializeAttributesSpec.SerializeAttributes
Test FullName: Unittests.Serialization.SerializeAttributesSpec.SerializeAttributes
Test Source: C:\Workspace\Unittests\Serialization\SerializeAttributes.cs : line 78
Test Outcome: Failed
Test Duration: 0:00:00,602
Result StackTrace:
bij ExtendedXmlSerializer.ExtensionModel.Content.Members.MemberExceptionHandlingExtension.MemberSerializer.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ExtensionModel\Content\Members\MemberExceptionHandlingExtension.cs:regel 94
bij ExtendedXmlSerializer.ContentModel.Members.MemberListWriter.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Members\MemberListWriter.cs:regel 36
bij ExtendedXmlSerializer.ContentModel.Serializer`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Serializer.cs:regel 47
bij ExtendedXmlSerializer.ContentModel.Content.Enclosure`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Content\Enclosure.cs:regel 51
bij ExtendedXmlSerializer.ContentModel.SerializerAdapter`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\SerializerAdapter.cs:regel 66
bij ExtendedXmlSerializer.Write`1.Execute(Writing`1 parameter) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Write.cs:regel 43
bij ExtendedXmlSerializer.Serializer`2.Serialize(TWrite writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Serializer.cs:regel 41
bij ExtendedXmlSerializer.ExtensionModel.Xml.ExtendedXmlSerializer.Serialize(XmlWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\ExtendedXmlSerializer.cs:regel 40
bij Unittests.Serialization.Support.Extensions.SerializeToFile(Object object, IExtendedXmlSerializer serializer, String fileName) in C:\Workspace\Unittests\Serialization\Support\Extensions.cs:regel 40
bij Unittests.Serialization.SerializeAttributesSpec.SerializeAttributes() in C:\Workspace\Unittests\Serialization\SerializeAttributes.cs:regel 119
----- Inner Stack Trace -----
bij System.Xml.XmlWellFormedWriter.ThrowInvalidStateTransition(Token token, State currentState)
bij System.Xml.XmlWellFormedWriter.AdvanceState(Token token)
bij System.Xml.XmlWellFormedWriter.WriteStartAttribute(String prefix, String localName, String namespaceName)
bij System.Xml.XmlWriter.WriteAttributeString(String localName, String value)
bij ExtendedXmlSerializer.ExtensionModel.Xml.XmlWriter.Content(IIdentity property, String content) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ExtensionModel\Xml\XmlWriter.cs:regel 120
bij ExtendedXmlSerializer.ContentModel.Format.ContextualWriter`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Format\ContextualWriter.cs:regel 40
bij ExtendedXmlSerializer.ContentModel.DecoratedWriter`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\DecoratedWriter.cs:regel 43
bij ExtendedXmlSerializer.ContentModel.DecoratedWriter`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\DecoratedWriter.cs:regel 43
bij ExtendedXmlSerializer.ContentModel.Serializer`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Serializer.cs:regel 47
bij ExtendedXmlSerializer.ContentModel.Properties.Property`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Properties\Property.cs:regel 47
bij ExtendedXmlSerializer.ContentModel.Properties.ConverterProperty`1.Write(IFormatWriter writer, T instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Properties\ConverterProperty.cs:regel 41
bij ExtendedXmlSerializer.ContentModel.GenericSerializerAdapter`1.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\GenericSerializerAdapter.cs:regel 36
bij ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Writer.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Members\MemberSerializers.cs:regel 107
bij ExtendedXmlSerializer.ContentModel.Members.MemberSerializer.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Members\MemberSerializer.cs:regel 46
bij ExtendedXmlSerializer.ContentModel.Members.PropertyMemberSerializer.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ContentModel\Members\PropertyMemberSerializer.cs:regel 36
bij ExtendedXmlSerializer.ExtensionModel.Content.Members.MemberExceptionHandlingExtension.MemberSerializer.Write(IFormatWriter writer, Object instance) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ExtensionModel\Content\Members\MemberExceptionHandlingExtension.cs:regel 90
Result Message:
System.InvalidOperationException : An exception was encountered while serializing member 'Unittests.Serialization.RootElement.Version'. Provided instance is 'Unittests.Serialization.RootElement'.
---- System.InvalidOperationException : Token StartAttribute in state Element Content would result in an invalid XML document..
Test 3
- With
EnableMemberExceptionHandling()
RootElement
has an attribute namedVersion
, which is NOT set.RootElement
has an elementBar
, which is set.
var c = new ConfigurationContainer()
.EnableMemberExceptionHandling()
.ConfigureType<RootElement>()
.Name("Root")
.Member(re => re.Version)
.Attribute()
.ConfigureType<Bar>()
.Create();
var r = new RootElement
{
//Version = "1",
Bar = new Bar { Name = "bar" },
};
r.SerializeToFile();
c.Cycle(r).Should().BeEquivalentTo(r);
which has this result:
<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="clr-namespace:Unittests.Serialization;assembly=Common.Unittests">
<Bar>
<Name>bar</Name>
</Bar>
</Root>
Test 4
- With
EnableMemberExceptionHandling()
RootElement
has an attribute namedVersion
, which is set.RootElement
has an elementBar
, which is NOT set.
var c = new ConfigurationContainer()
.EnableMemberExceptionHandling()
.ConfigureType<RootElement>()
.Name("Root")
.Member(re => re.Version)
.Attribute()
.ConfigureType<Bar>()
.Create();
var r = new RootElement
{
Version = "1",
//Bar = new Bar { Name = "bar" },
};
r.SerializeToFile(c, @"C:\Users\johan.SERVER-PARLANDO\AppData\Local\Temp\xml.xml");
c.Cycle(r).Should().BeEquivalentTo(r);
<?xml version="1.0" encoding="utf-8"?>
<Root Version="1" xmlns="clr-namespace:Common.Unittests.Serialization;assembly=Common.Unittests" />
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Token StartAttribute in state Element Content would result ...
Problem solved by following the statement as given below. Step 1: Start the element with XML tag name. writer.WriteStartElement("TagName");.
Read more >Token StartAttribute in state Element Content would result ...
This seems to have something to do with EnableMemberExceptionHandling() . For this sample I have the following classes: public class RootElement ...
Read more >NAV2018 : Token StartAttribute XML Error
Processing of message 'al/createPackage' failed with error: 'Token StartAttribute in state Element Content would result in an invalid XML ...
Read more >Token StartElement in state EndRootElement would result ...
This article provides a resolution for the Token StartElement in state EndRootElement would result in an invalid XML document error that may ...
Read more >Token startattribute in state element content would result in ...
token startattribute in state element content would result in an invalid xml document in UiPath. What is the solution for this?
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That would be awesome
This seems to be fixed.
Thanks