mscorlib.XmlSerializers.DLL的FileNotFoundException,它不存在

Kei*_*ith 12 .net c# serialization assemblies

我正在使用XmlSerializer来反序列化mscorelib.dll中的特定类型

XmlSerializer ser = new XmlSerializer( typeof( [.Net type in System] ) );
return ([.Net type in System]) ser.Deserialize( new StringReader( xmlValue ) );
Run Code Online (Sandbox Code Playgroud)

这会FileNotFoundException在加载程序集时抛出一个catch :

"无法加载文件或程序集'mscorlib.XmlSerializers,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'或其中一个依赖项.系统找不到指定的文件."

FusionLog:

=== 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.
Run Code Online (Sandbox Code Playgroud)

据我所知,没有mscorlib.XmlSerializers.DLL,我认为.Net的自动生成的DLL名称正在寻找序列化程序.

在编译优化序列化时,您可以选择创建myApplication.XmlSerializers.DLL,因此我认为这是框架检查它的一部分.

问题是,这似乎导致加载应用程序的延迟 - 此时似乎挂起了几秒钟.

任何想法如何避免或加快它?

Wil*_*ean 2

我现在猜。但:

  1. 系统可能正在为整个 mscorlib 生成序列化器,这可能非常慢。
  2. 您可以通过将系统类型包装在您自己的类型中并对其进行序列化来避免这种情况 - 然后您将获得您自己的程序集的序列化器。
  3. 您也许可以使用 sgen.exe 为 mscorlib 构建序列化器,这是在集成到 VS 之前构建序列化器 dll 的旧方法。