Question: Is Singleton serializer configured during app-start supported?
See original GitHub issueHello,
We’re having problems when using the serializer as a singleton - initialized once during application startup. Is this a supported scenario or should the serializer be created every time it’s used?
See https://github.com/jhranac/XmlSerializerTest for minimum repro-repo
The issue When we create the serializer some DLLs are still not loaded. The AssemblyLoader attempts to rectify this issue, but the “Assembly.Load” does not load .net framework libraries (e.g. System.Drawing). The issue applies to both serialization and deserialization.
Both end up with an exception:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Drawing' or one of its dependencies. The system cannot find the file specified.
Source=mscorlib
StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at ExtendedXmlSerializer.ReflectionModel.AssemblyLoader.Get(String parameter)
at ExtendedXmlSerializer.ContentModel.Reflection.PartitionedTypeCandidates.Create(IIdentity parameter)
at ExtendedXmlSerializer.Core.Sources.StructureCacheBase`2.CreateStructure(TKey parameter)
at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey key, CreateValueCallback createValueCallback)
at ExtendedXmlSerializer.Core.Sources.StructureCacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ContentModel.Reflection.TypeCandidates.Get(IIdentity parameter)
at ExtendedXmlSerializer.ContentModel.Reflection.Types.Create(IIdentity parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.IsMember(IMember profile)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Content(IMember profile, IMemberAccess access)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Get(IMember parameter)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializations.Create(TypeInfo parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ContentModel.Members.InstanceMemberSerializations.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Members.MemberedContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ContentModel.Content.RecursionAwareContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ExtensionModel.Xml.CustomSerializationExtension.Contents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.Cache`2.Create(TKey parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ExtensionModel.References.DeferredContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Members.DefaultMemberContents.Get(IMember parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.DecoratedSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.DecoratedSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Content(IMember profile, IMemberAccess access)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Get(IMember parameter)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializations.Create(TypeInfo parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ContentModel.Members.InstanceMemberSerializations.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Members.MemberedContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ContentModel.Content.RecursionAwareContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ExtensionModel.Xml.CustomSerializationExtension.Contents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.Cache`2.Create(TKey parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ExtensionModel.References.DeferredContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Members.VariableTypeMemberContents.Get(IMember parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.DecoratedSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.DecoratedSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Content(IMember profile, IMemberAccess access)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializers.Get(IMember parameter)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at ExtendedXmlSerializer.ContentModel.Members.MemberSerializations.Create(TypeInfo parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ContentModel.Members.InstanceMemberSerializations.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Members.MemberedContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.Core.Sources.ConditionalSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ContentModel.Content.RecursionAwareContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ExtensionModel.Xml.CustomSerializationExtension.Contents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.Cache`2.Create(TKey parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ExtensionModel.References.DeferredContents.Get(TypeInfo parameter)
at ExtendedXmlSerializer.ContentModel.Content.Serializers.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.CoercedParameter`3.Get(TFrom parameter)
at ExtendedXmlSerializer.Core.Sources.DelegatedSource`2.Get(TParameter parameter)
at ExtendedXmlSerializer.ExtensionModel.References.ReferenceAwareSerializers.Get(TypeInfo parameter)
at ExtendedXmlSerializer.Core.Sources.Cache`2.Create(TKey parameter)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at ExtendedXmlSerializer.Core.Sources.CacheBase`2.Get(TKey key)
at ExtendedXmlSerializer.ExtensionModel.Xml.Write.Execute(Writing parameter)
at ExtendedXmlSerializer.ExtensionModel.Xml.Serializer.Serialize(XmlWriter writer, Object instance)
at ExtendedXmlSerializer.ExtensionModel.Xml.ExtendedXmlSerializer.Serialize(XmlWriter writer, Object instance)
at ExtendedXmlSerializer.ExtensionModel.Xml.InstanceFormatter.Get(Object parameter)
at ExtendedXmlSerializer.ExtensionMethodsForSerialization.Serialize(IExtendedXmlSerializer this, Object instance)
at SerializerTests.Tests.UnitTest1.SerializationTest() in E:\bugtests\ExtendedXmlSerializer\SerializerTests\XmlSerializerTest\SerializerTests.Tests\UnitTest1.cs:line 19
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Is a single config object a bad idea?
Using a Singleton in this case is inappropriate as having more than one of a configuration reader should not cause an error state...
Read more >java - How to deal with Singleton along with Serialization
Firstly, singletons don't need serialization, because if you deserialized it, and then deserialized singleton != YourSingleton.getInstance(), it ...
Read more >Dependency Injection - Singleton? · Issue #504
If I want to pass in a class as a dependency it will be created every time. So a feature to create singleton...
Read more >Java Singleton Design Pattern Best Practices with Examples
1. Eager initialization ... If your singleton class is not using a lot of resources, this is the approach to use. But in...
Read more >Firebase Apple SDK Release Notes - Google
The configure flow now validates existence of an APNs token before fetching an FCM token (#10742). This also addresses the scenario mentioned in...
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
Hi @Mike-EEE ! Looking good. It loads the correct assembly from GAC now.
Alright @jhranac see if this works for you and let me know of any problems you find: https://www.nuget.org/packages/ExtendedXmlSerializer/