【发布时间】:2010-09-05 22:38:16
【问题描述】:
我正在使用 XmlSerializer 反序列化 mscorelib.dll 中的特定类型
XmlSerializer ser = new XmlSerializer( typeof( [.Net type in System] ) );
return ([.Net type in System]) ser.Deserialize( new StringReader( xmlValue ) );
这会在程序集加载时抛出一个捕获的FileNotFoundException:
"无法加载文件或程序集 'mscorlib.XmlSerializers, 版本=2.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089' 或 它的依赖项之一。系统 找不到指定的文件。”
融合日志:
=== Pre-bind state information ===
LOG: User = ###
LOG: DisplayName = mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86
(Fully-specified)
LOG: Appbase = file:///C:/localdir
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\localdir\bin\Debug\appname.vshost.exe.Config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: mscorlib.XmlSerializers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.DLL.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers.EXE.
LOG: Attempting download of new URL file:///C:/localdir/bin/Debug/mscorlib.XmlSerializers/mscorlib.XmlSerializers.EXE.
据我所知,没有 mscorlib.XmlSerializers.DLL,我认为 DLL 名称是由 .Net 自动生成的,用于寻找序列化程序。
在编译以优化序列化时,您可以选择创建 myApplication.XmlSerializers.DLL,因此我认为这是框架对其进行检查的一部分。
问题在于,这似乎会导致加载应用程序出现延迟 - 此时它似乎会挂起几秒钟。
有什么办法可以避免或加快速度吗?
【问题讨论】:
-
我正在处理的类型是
RSAParameters,它被用作某些系统密码学的一部分。我现在已经通过另一种方式存储加密密钥并自己创建一个新的 RSAParameters 来解决这个问题。想要序列化(即加密/解密密钥)似乎是一件相对常见的事情。 -
我在尝试运行测试工具 Ranorex 时遇到了这个问题。我现在有一个解决方法,但无法修复它,他们的支持人员尚未与我联系。 :-/
-
检查生成的 mscorlib.XmlSerializers.dll 和您的项目的 .NET 版本。它必须相同。看看这个:stackoverflow.com/a/52848813/5639198
-
@Sashus 感谢您的帮助,但这个问题是十多年前的问题,我无法再访问有此问题的项目。
标签: c# .net serialization assemblies