ArgumentNullException when Deserializing Inherit Class with empty Migration
See original GitHub issueI’ve found an Issue in my Project with deserializing via a Migration. I’ve created the following Example to reproduce the behaviour:
using ExtendedXmlSerializer;
using ExtendedXmlSerializer.Configuration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Linq;
namespace Test
{
class IssueExample
{
static void Main(string[] args)
{
var serializer = new ConfigurationContainer().Type<Base>().AddMigration(new EmptyMigration()).Create();
var container = new Container { Content = new AnotherNameSpace.Inherit() };
var xml = serializer.Serialize(container);
var loaded = serializer.Deserialize<Container>(xml); //Throws System.ArgumentNullException
}
}
public class Container
{
public Base Content { get; set; }
}
public class Base { }
namespace AnotherNameSpace
{
public class Inherit : Base { }
}
public class EmptyMigration : IEnumerable<Action<XElement>>
{
public IEnumerator<Action<XElement>> GetEnumerator()
{
yield return x => { }; //Do nothing
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
The Key-Elements are the inherit class inside the container object and the empty migration which changes something. If you remove the namespace “AnotherNameSpace”, another exception appears. The whole thing has something to do with namespaces. In the following the stacktrace:
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Parametername: key
Source=mscorlib
StackTrace:
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key) in ExtendedXmlSerializer\Core\Sources\CacheBase.cs:line 34
at ExtendedXmlSerializer.ContentModel.Identification.IdentityStore.Get(String name, String identifier) in ExtendedXmlSerializer\ContentModel\Identification\IdentityStore.cs:line 10
at ExtendedXmlSerializer.ExtensionModel.Xml.IdentityMapper.Get(String name, String identifier) in ExtendedXmlSerializer\ExtensionModel\Xml\IdentityMapper.cs:line 17
at ExtendedXmlSerializer.ContentModel.Reflection.TypePartReflector.Create(TypeParts parameter) in ExtendedXmlSerializer\ContentModel\Reflection\TypePartReflector.cs:line 24
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key) in ExtendedXmlSerializer\Core\Sources\CacheBase.cs:line 34
at ExtendedXmlSerializer.ContentModel.Reflection.TypeParser.Create(String parameter) in ExtendedXmlSerializer\ContentModel\Reflection\TypeParser.cs:line 22
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key) in ExtendedXmlSerializer\Core\Sources\CacheBase.cs:line 34
at ExtendedXmlSerializer.ContentModel.Reflection.ReflectionParser.Create(String parameter) in ExtendedXmlSerializer\ContentModel\Reflection\ReflectionParser.cs:line 41
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key) in ExtendedXmlSerializer\Core\Sources\CacheBase.cs:line 34
at ExtendedXmlSerializer.ExtensionModel.Xml.FormatReaderContext.Get(String parameter) in ExtendedXmlSerializer\ExtensionModel\Xml\FormatReaderContext.cs:line 19
at ExtendedXmlSerializer.ExtensionModel.Xml.XmlReader.Get(String parameter) in ExtendedXmlSerializer\ExtensionModel\Xml\XmlReader.cs:line 28
at ExtendedXmlSerializer.ContentModel.Format.ParsedContent`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Format\ParsedContent.cs:line 16
at ExtendedXmlSerializer.ContentModel.Format.ContextualReader`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Format\ContextualReader.cs:line 17
at ExtendedXmlSerializer.ContentModel.DecoratedReader`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\DecoratedReader.cs:line 26
at ExtendedXmlSerializer.ContentModel.Reflection.TypedParsingReader.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Reflection\TypedParsingReader.cs:line 15
at ExtendedXmlSerializer.ContentModel.TrackingReader`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\TrackingReader.cs:line 13
at ExtendedXmlSerializer.ContentModel.Members.Extensions.GetIfAssigned[T](IReader`1 this, IFormatReader reader) in ExtendedXmlSerializer\ContentModel\Members\Extensions.cs:line 12
at ExtendedXmlSerializer.ContentModel.Serializer`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Serializer.cs:line 22
at ExtendedXmlSerializer.ContentModel.Properties.Property`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Properties\Property.cs:line 17
at ExtendedXmlSerializer.ContentModel.Reflection.Classification.FromAttributes(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Reflection\Classification.cs:line 37
at ExtendedXmlSerializer.ContentModel.Reflection.Classification.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Reflection\Classification.cs:line 31
at ExtendedXmlSerializer.ContentModel.Reflection.Activation.RuntimeActivator.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Reflection\Activation.cs:line 61
at ExtendedXmlSerializer.ExtensionModel.Xml.XmlInnerContentActivator.Get(IFormatReader parameter) in ExtendedXmlSerializer\ExtensionModel\Xml\XmlInnerContentActivator.cs:line 20
at ExtendedXmlSerializer.ContentModel.Content.InnerContentReader.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Content\InnerContentReader.cs:line 21
at ExtendedXmlSerializer.ContentModel.Members.Extensions.GetIfAssigned[T](IReader`1 this, IFormatReader reader) in ExtendedXmlSerializer\ContentModel\Members\Extensions.cs:line 12
at ExtendedXmlSerializer.ContentModel.Serializer`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Serializer.cs:line 22
at ExtendedXmlSerializer.ExtensionModel.Xml.MigrationsExtension.Contents.Serializer.Get(IFormatReader parameter) in ExtendedXmlSerializer\ExtensionModel\Xml\MigrationsExtension.cs:line 149
at ExtendedXmlSerializer.ContentModel.Members.Extensions.GetIfAssigned[T](IReader`1 this, IFormatReader reader) in ExtendedXmlSerializer\ContentModel\Members\Extensions.cs:line 12
at ExtendedXmlSerializer.ContentModel.Serializer`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Serializer.cs:line 22
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializer.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Members\MemberSerializer.cs:line 22
at ExtendedXmlSerializer.ContentModel.Members.MemberHandler.Handle(IInnerContent contents, IMemberSerializer member) in ExtendedXmlSerializer\ContentModel\Members\MemberHandler.cs:line 13
at ExtendedXmlSerializer.ContentModel.Content.InnerContentServices.Handle(IInnerContent contents, IMemberSerializer member) in ExtendedXmlSerializer\ContentModel\Content\InnerContentServices.cs:line 41
at ExtendedXmlSerializer.ContentModel.Members.MemberInnerContentHandler.IsSatisfiedBy(IInnerContent parameter) in ExtendedXmlSerializer\ContentModel\Members\MemberInnerContentHandler.cs:line 29
at ExtendedXmlSerializer.ContentModel.Content.InnerContentReader.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Content\InnerContentReader.cs:line 26
at ExtendedXmlSerializer.ContentModel.Members.Extensions.GetIfAssigned[T](IReader`1 this, IFormatReader reader) in ExtendedXmlSerializer\ContentModel\Members\Extensions.cs:line 12
at ExtendedXmlSerializer.ContentModel.Serializer`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\Serializer.cs:line 22
at ExtendedXmlSerializer.ContentModel.SerializerAdapter`1.Get(IFormatReader parameter) in ExtendedXmlSerializer\ContentModel\SerializerAdapter.cs:line 41
at ExtendedXmlSerializer.ExtensionModel.Xml.Read.Get(XmlReader parameter) in ExtendedXmlSerializer\ExtensionModel\Xml\Read.cs:line 26
at ExtendedXmlSerializer.ExtensionModel.Xml.Serializer.Deserialize(XmlReader reader) in ExtendedXmlSerializer\ExtensionModel\Xml\Serializer.cs:line 21
at ExtendedXmlSerializer.ExtensionModel.Xml.ExtendedXmlSerializer.Deserialize(XmlReader reader) in ExtendedXmlSerializer\ExtensionModel\Xml\ExtendedXmlSerializer.cs:line 18
at ExtendedXmlSerializer.ExtensionMethodsForSerialization.Deserialize[T](IExtendedXmlSerializer this, XmlReaderSettings settings, Stream stream) in ExtendedXmlSerializer\ExtensionMethodsForSerialization.cs:line 145
at ExtendedXmlSerializer.ExtensionMethodsForSerialization.Deserialize[T](IExtendedXmlSerializer this, XmlReaderSettings settings, String data) in ExtendedXmlSerializer\ExtensionMethodsForSerialization.cs:line 121
at ExtendedXmlSerializer.ExtensionMethodsForSerialization.Deserialize[T](IExtendedXmlSerializer this, String data) in ExtendedXmlSerializer\ExtensionMethodsForSerialization.cs:line 109
at Test.IssueExample.Main(String[] args) in IssueExample.cs:line 17
This exception was originally thrown at this call stack:
[External Code]
ExtendedXmlSerializer.Core.Sources.CacheBase<TKey, TValue>.Get(TKey) in CacheBase.cs
ExtendedXmlSerializer.ContentModel.Identification.IdentityStore.Get(string, string) in IdentityStore.cs
ExtendedXmlSerializer.ExtensionModel.Xml.IdentityMapper.Get(string, string) in IdentityMapper.cs
ExtendedXmlSerializer.ContentModel.Reflection.TypePartReflector.Create(ExtendedXmlSerializer.ContentModel.Conversion.TypeParts) in TypePartReflector.cs
[External Code]
ExtendedXmlSerializer.Core.Sources.CacheBase<TKey, TValue>.Get(TKey) in CacheBase.cs
ExtendedXmlSerializer.ContentModel.Reflection.TypeParser.Create(string) in TypeParser.cs
[External Code]
ExtendedXmlSerializer.Core.Sources.CacheBase<TKey, TValue>.Get(TKey) in CacheBase.cs
...
[Call Stack Truncated]
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
EF migration shows empty Up() Down() methods
It's like it can't find the new Code-First classes I have added. This is my command: add-migration "1.2" -verbose -ProjectName "MyEFproject".
Read more >Notice of Support Availability and Expectations · Issue #383
Mike-E-angelo mentioned this issue on Jul 15, 2020. ArgumentNullException when Deserializing Inherit Class with empty Migration #414.
Read more >ArgumentOutOfRangeException Class (System)
The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked...
Read more >InvalidOperationException Class (System)
Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (Inherited from Exception) ...
Read more >Why inherit a class without adding properties?
The main reason why interfaces and inheritance are different here is because you can only inherit from one class, but you can implement...
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
It works just perfect. Older save can still be migrated and desirialized!
Woohoo! Glad to hear. Please let me know if you encounter any further issues. I will slate the fix release for next Tuesday and update here when available on Nuget. Please use the preview builds until then. 👍