.NET 4.5中的序列化异常 [英] Serialization Exception in .NET 4.5

查看:97
本文介绍了.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

XslCompiledTransform对象将使用GetManifestResourceStream的XmlReader加载到嵌入式.xslt文件中,但我已经确认它可以正确获取该信息。

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?

这是在Windows 8计算机上,但是我在server2008r2 OS上经历过

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

推荐答案

.NET 4.5遇到相同的错误。我仅在使用nunit 2.6+时看到错误。当您在子AppDomain中使用存储在CallContext中的对象初始化XmlSerializer时,似乎会发生这种情况。如果在子AppDomain中将ApplicationBase(bin路径)设置为其他值,则无法解析CallContext中对象的类型。您可以在Fusion Log Viewer中看到程序集绑定错误: http:// msdn。 microsoft.com/en-us/library/e74a18c4.aspx

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

就我而言,如果我将其中类型的程序集复制到nunits bin-路径,错误消失。当然,这不是可行的解决方案。

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?

编辑:我通过让类型继承MarshalByRefObject来修复它:在将Project从vs2005迁移到vs2010(MSTest)后无法在UnitTest中解析类型。

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

编辑2:替代方法是调用System。在失败的代码之前出现Configuration.ConfigurationManager.GetSection( dummy)。

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

这篇关于.NET 4.5中的序列化异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆