Deserializer Can't find a Class Program-ClassA (Should be Program.ClassA)
See original GitHub issueRunning the below code results in the following error “ExtendedXmlSerializer.Core.Sprache.ParseException: ‘An attempt was made to parse the identity ‘clr-namespace:;assembly=StackTypeSerialization:Program-ClassA’, but no type could be located with that name.’”. using release 2.1.15 targeting .Net Core 2.1
using ExtendedXmlSerializer.Configuration;
using System.Collections.Generic;
using System.Xml;
public class Program
{
public static void Main()
{
var outList = new List<ClassA>();
var classB = new ClassB();
var classC = new ClassC();
outList.Add(new ClassA()
{
blah = "Test1",
InterfaceConcreteTypeA = new ClassB() { TestInterfaceProperty = "Blah1", TestConcretePropertyB = "Blah1" },
InterfaceConcreteTypeB = new ClassC() { TestInterfaceProperty = "Blah2", TestConcretePropertyC = "Blah2" }
});
outList.Add(new ClassA()
{
blah = "Test2",
InterfaceConcreteTypeA = new ClassB(),
InterfaceConcreteTypeB = new ClassC()
});
outList.Add(new ClassA()
{
blah = "Test3",
InterfaceConcreteTypeA = new ClassB() { TestInterfaceProperty = "Blah3", TestConcretePropertyB = "Blah3" },
InterfaceConcreteTypeB = new ClassC() { TestInterfaceProperty = "Blah3", TestConcretePropertyC = "Blah3" }
});
var serializer = new ConfigurationContainer().Create();
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t"
};
using (XmlWriter writer = XmlWriter.Create("Test.xml", settings))
{
serializer.Serialize(writer, outList.ToArray());
}
List<ClassA> inList = new List<ClassA>();
using (XmlReader reader = XmlReader.Create("Test.xml", new XmlReaderSettings { IgnoreWhitespace = false }))
{
inList = (List<ClassA>)serializer.Deserialize(reader);
}
}
public class ClassA
{
public string blah { get; set; }
public InterfaceA InterfaceConcreteTypeA { get; set; }
public InterfaceA InterfaceConcreteTypeB { get; set; }
}
public class ClassB : InterfaceA
{
public string TestInterfaceProperty { get; set; }
public string TestConcretePropertyB { get; set; }
}
public class ClassC : InterfaceA
{
public string TestInterfaceProperty { get ; set; }
public string TestConcretePropertyC { get; set; }
}
public interface InterfaceA
{
string TestInterfaceProperty { get; set; }
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:19 (9 by maintainers)
Top Results From Across the Web
JSON.NET won't deserialize class correctly
The property names of that class match the ctor argument names, so I cannot understand why I get wrong values in there during...
Read more >Should custom deserialization happen in a constructor or ...
No, it should not. Serialization is orthogonal to the object and thus should be kept outside. Custom serialization belongs in a ...
Read more >Getting Started with Custom Deserialization in Jackson
This quick tutorial will illustrate how to use Jackson 2 to deserialize JSON using a custom Deserializer.
Read more >How to serialize and deserialize JSON using C# - .NET
Copy the JSON that you need to deserialize. Create a class file and delete the template code. Choose Edit > Paste Special >...
Read more >How to serialize properties of derived classes with System. ...
In this article, you will learn how to serialize properties of derived classes with the System.Text.Json namespace.
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
So I tried the same thing with .net 4.5. Same result.
Then I tried moving all of the classes to their own file. GUESS WHAT!!! it worked… this does not make ANY SENSE. It should not matter what file they are in.
Then I thought, wait a minute there is no enclosing namespace {} in the main program.cs file… So I added one and put the classes back in that file and it worked…
for posterity, this is complete working code
I am not sure what you mean by “secretly failing without telling me”, it was definitely throwing an error on deserialize.