c# - 使用 Spoon Studio .Net 4.0 构建的应用程序中带有 XmlSerializers 的 FileNotFoundException

标签 c# visual-studio-2012 xml-serialization clr4.0

我在使用 Spoon Studio 和 .Net 4.0 打包的虚拟化应用程序中遇到以下异常

Exception='System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\temp\Serialization\mf3je3jx.dll' or one of its dependencies. The system cannot find the file specified.
File name: 'file:///C:\temp\Serialization\mf3je3jx.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity)
   at System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly()
   at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
   at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
   at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace)
   at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)

在我们使用 .Net 3.5 之前,它工作正常,但在迁移到 .Net 4.0 包后,我们开始看到这个错误。

我知道解决这个问题的一种方法是预先生成 XmlSerializers,但在我们的例子中,我们有多个加载项也需要重建,我们希望避免这样做。

我的问题是为什么会发生这种情况?为什么运行时无法在运行时生成序列化程序?我可以看到在临时目录中生成了 .cs 和 .out 文件(dll 也会暂时生成并立即删除)。

如果我在没有虚拟化的情况下运行我的应用程序,它可以正常工作并且能够构建和加载内存中序列化程序。在这两种情况下,运行应用程序的用户都是相同的。

欢迎提出任何建议。

It's a separate problem but I'm unable to debug this within VS or windbg (I get clr version mismatch error b/w VS and Application)

reason being: installing VS12/.Net 4.5 on the machine upgrades the CLR version number to 4.0.30319.17929 whereas application uses 4.0.30319.1. and VS doesn't allow me to attach to this application

最佳答案

我们已找到问题。

Spoon Studio 为 .Net 4.0 使用的默认 .Net 图像中没有所有必需的程序集。

这是 Spoon Studio 中的错误。我通过从 SpoonStudio 团队获取新的自定义图像来实现它。

关于c# - 使用 Spoon Studio .Net 4.0 构建的应用程序中带有 XmlSerializers 的 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14241169/

相关文章:

c# - 每页使用多个 @Html.Action() 是否很昂贵?

c# - unity SSLStream AuthenticateAsClient 给SslPolicyErrors.RemoteCertificateNotAvailable

c++ - Qt : After installation of VS2012 LNK1123 failure during conversion to COFF

c++ - 构建 LuaBind 的问题 [C++]

.net - 如何控制.NET DataContract序列化,使其使用XML属性而不是元素?

c# - 如何获得应用程序启动所需的时间?

c# - 将对象从 Controller 传递给 JavaScript JQuery

c++ - Visual Studio 2012 中的单元测试 C++ 控制台应用程序

c# - 在不创建新类的情况下反序列化字符串列表?

c# - InvalidOperationException 错误反射(reflect)类