C# 无法加载文件或程序集 'MyAssembly.XmlSerializers
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17755559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not load file or assembly 'MyAssembly.XmlSerializers
提问by sanjeev40084
I took a memory dump of IIS and while analyzing i found the error that said 'Could not load file or assembly MyAssemblyName.XmlSerializers'. In my code i am using XmlSerializer class to serialize and deserialize xml contents from xml file to custom object. When the project gets build it only creates MyAssembly.dll and MyAssembly.pdb file but not the MyAssembly.XmlSerializers.dll. Does anyone know how to enable my project to create xmlserializers.dll file?
我对 IIS 进行了内存转储,在分析时我发现了错误,指出'Could not load file or assembly MyAssemblyName.XmlSerializers'。在我的代码中,我使用 XmlSerializer 类将 xml 内容从 xml 文件序列化和反序列化到自定义对象。当项目被构建时,它只会创建 MyAssembly.dll 和 MyAssembly.pdb 文件,而不是 MyAssembly.XmlSerializers.dll。有谁知道如何让我的项目创建 xmlserializers.dll 文件?
Note: In project build tab, 'Generate serialization assembly is set to Auto.
注意:在项目构建选项卡中,“生成序列化程序集”设置为“自动”。
Thanks.
谢谢。
回答by Bok McDonagh
There's an answer already here. Apparently this is "expected behaviour" that MS isn't going to fix.
有已经是答案在这里。显然,这是 MS 不会修复的“预期行为”。
The first comment has a workaround:
第一条评论有一个解决方法:
One of the possible ways to get rid of this problem is check "Just my code" option in Tools -> Options -> Debugging -> General options
解决此问题的一种可能方法是在工具 -> 选项 -> 调试 -> 常规选项中检查“仅我的代码”选项
回答by LIDEN
You can also generate this assembly using Sgen.exe
您还可以使用Sgen.exe生成此程序集
For me it's located in: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
对我来说,它位于: C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools
1. open cmd command
2. cd yourProjectPath
3. sgen Project.dll
The following command creates an assembly named Project.XmlSerializers.dll for serializing all the types contained in the assembly named Project.dll.
以下命令创建一个名为 Project.XmlSerializers.dll 的程序集,用于序列化名为 Project.dll 的程序集中包含的所有类型。
回答by Sashus
When you create MyAssembly.XmlSerializers.dll make sure it is same .NET version as your project. You can check that using software as dotPeek or ILSpy. I had similar problem when creating xmlserializers for my .NET 3.5 solution from visual studio, generate serialization assembly was set on for project but Sgen.exe was used from C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools and should be from C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin. If your solution is in .NET 3.5 MyAssembly.XmlSerializers.dll must also be in .NET 3.5
创建 MyAssembly.XmlSerializers.dll 时,请确保它与项目的 .NET 版本相同。您可以使用 dotPeek 或 ILSpy 等软件进行检查。我在从 Visual Studio 为我的 .NET 3.5 解决方案创建 xmlserializers 时遇到了类似的问题,为项目设置了生成序列化程序集,但从 C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\ 使用了 Sgen.exe bin\NETFX 4.6.1 Tools 应该来自 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin。如果您的解决方案在 .NET 3.5 中,则 MyAssembly.XmlSerializers.dll 也必须在 .NET 3.5 中