Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialization Exception in .NET 4.5

I'm getting this stack trace when I call:

XslCompiledTransform.Transform(XmlDocument.DocumentElement.CreateNavigator(), null, StringWriter)


System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Runtime.Serialization.SerializationException: Type is not resolved for member --MyProject stuff
   at System.AppDomain.GetHostEvidence(Type type)
   at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType)
   at System.Security.Policy.Evidence.GenerateHostEvidence(Type type, Boolean hostCanGenerate)
   at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)
   at System.Security.Policy.Evidence.RawEvidenceEnumerator.MoveNext()
   at System.Security.Policy.Evidence.EvidenceEnumerator.MoveNext()
   at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName)
   at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
   at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
   at System.Configuration.ClientConfigurationHost.get_HasRoamingConfig()
   at System.Configuration.ClientConfigurationHost.IsConfigRecordRequired(String configPath)
   at System.Configuration.BaseConfigurationRecord.hlNeedsChildFor(String configName)
   at System.Configuration.Internal.InternalConfigRoot.GetConfigRecord(String configPath)
   at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationManager.PrepareConfigSystem()
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at System.Xml.XmlConfiguration.XmlReaderSection.get_ProhibitDefaultUrlResolver()
   at System.Xml.XmlTextReaderImpl.get_IsResolverNull()
   at System.Xml.Xsl.QueryReaderSettings..ctor(XmlReader reader)
   at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
   at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
   at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
   at MyProject

The XslCompiledTransform object Loads an XmlReader that uses GetManifestResourceStream to an embedded .xslt file, but I have confirmed that it is getting that information correctly.

I've looked at it quite a bit and narrowed it down to this call, but I am not sure where to go from here. Has anyone else experienced this?

This was on a Windows 8 machine, but I have experienced it on server2008r2 OS

like image 534
ReddShepherd Avatar asked Dec 03 '22 23:12

ReddShepherd


1 Answers

I am experiencing the same error with .NET 4.5. I only see the error when using nunit 2.6+. It seems to happen when you initialize an XmlSerializer in a sub-AppDomain, with objects stored in the CallContext. The type of the object in the CallContext can't be resolved if the ApplicationBase (the bin-path) is set to something different in the sub-AppDomain. You can see the assembly binding error in the Fusion Log Viewer: http://msdn.microsoft.com/en-us/library/e74a18c4.aspx

In my case, if I copy the assembly with the type in it to nunits bin-path, the error goes away. This is of course not a viable solution.

Have you found the root cause for the error?

EDIT: I fixed it by letting the type inherit MarshalByRefObject: Type cant be resolve in UnitTest after migrating Project from vs2005 to vs2010 (MSTest)

EDIT 2: Alternative fix is to call System.Configuration.ConfigurationManager.GetSection("dummy") prior to the code that fails.

like image 54
Andreas Kromann Avatar answered Dec 26 '22 00:12

Andreas Kromann