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

前端之家收集整理的这篇文章主要介绍了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的旧方式.

原文链接:https://www.f2er.com/csharp/95226.html

猜你在找的C#相关文章