c# – 用于mscorlib.XmlSerializers.DLL的FileNotFoundException,不存在

我正在使用XmlSerializer反序列化mscorelib.dll中的特定类型
XmlSerializer ser = new XmlSerializer( typeof( [.Net type in System] ) );
return ([.Net type in System]) ser.Deserialize( new StringReader( xmlValue ) );

当加载程序集时,这会引发捕获的FileNotFoundException:

“Could not load file or assembly
‘mscorlib.XmlSerializers,
Version=2.0.0.0,Culture=neutral,
PublicKeyToken=b77a5c561934e089’ or
one of its dependencies. The system
cannot find the file specified.”

FusionLog:

=== Pre-bind state information ===
LOG: User = ###
LOG: DisplayName = mscorlib.XmlSerializers,Version=2.0.0.0,PublicKeyToken=b77a5c561934e089,processorArchitecture=x86
 (Fully-specified)
LOG: Appbase = file:///C:/localdir
LOG: Initial PrivatePath = NULL
Calling assembly : System.Xml,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,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,因此我认为这是框架检查的一部分.

问题在于,这似乎是导致加载应用程序的延迟 – 在这一点上似乎挂了几秒钟.

任何想法如何避免这种或加速?

解决方法

我现在猜测但:

>系统可能会为整个mscorlib生成一个串行化器,这可能非常慢.>你可以通过将系统类型包装在你自己的类型中,然后序列化,你可以避免这种情况 – 然后你会得到一个你自己的程序集的序列化程序.>您可能可以使用sgen.exe构建mscorlib的序列化程序,这是在集成到VS之前构建串行化程序dll的旧方式.

相关文章

1:最直白的循环遍历方法,可以分为遍历key--value键值对以及...
private void ClearTextBox(){ foreach (var control in pnl...
原文叫看《墨攻》理解IOC概念 2006年多部贺岁大片以让人应接...
右击文件夹->安全选项卡->添加->高级-...