Serialization Exception in .NET 4.5
我在调用时得到了这个堆栈跟踪:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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 文件中,但我已确认它可以正确获取该信息。
我已经看了很多,并将其缩小到这个电话,但我不知道从这里去哪里。有没有其他人经历过这种情况?
这是在 Windows 8 机器上,但我在 server2008r2 操作系统上体验过它
我在使用 .NET 4.5 时遇到了同样的错误。我只在使用 nunit 2.6 时看到错误。当您在子 AppDomain 中使用存储在 CallContext 中的对象初始化 XmlSerializer 时,似乎会发生这种情况。如果在子 AppDomain 中将 ApplicationBase(bin-path)设置为不同的值,则无法解析 CallContext 中的对象类型。您可以在 Fusion Log Viewer 中看到程序集绑定错误:http://msdn.microsoft.com/en-us/library/e74a18c4.aspx
在我的例子中,如果我将带有类型的程序集复制到 nunits bin-path,错误就会消失。这当然不是一个可行的解决方案。
您找到错误的根本原因了吗?
编辑:我通过让类型继承 MarshalByRefObject 来修复它:将项目从 vs2005 迁移到 vs2010 (MSTest)
后,类型无法在 UnitTest 中解析
编辑 2:替代解决方法是在代码失败之前调用 System.Configuration.ConfigurationManager.GetSection("dummy")。