可移植类库中的 FileNotFoundException?
我有 3 个程序集、一个 WP7 应用程序(针对 7.0)、一个 Web 服务项目(运行 4.0)和一个可移植类库(根据模板构建并针对 WP7、SL4 和 .NET 4.0),其中包含常用类型介于前两者之间。
当在本地运行(在 IIS Express 中)时,一切正常,但是当针对 Web 服务程序集的已部署实例(在我几乎无法控制的远程 IIS 服务器上)运行时,则会失败,并出现以下异常:
System.IO.FileNotFoundException:无法加载文件或程序集 'System.Xml.Serialization,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089' 或其依赖项之一。这 系统找不到指定的文件。文件名: 'System.Xml.Serialization,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089' ---> System.IO.FileNotFoundException: 无法加载文件或程序集“System.Xml.Serialization, 版本=2.0.5.0,文化=中性,PublicKeyToken=31bf3856ad364e35, Retargetable=Yes' 或其依赖项之一。系统找不到 指定的文件。文件名:'System.Xml.Serialization, 版本=2.0.5.0,文化=中性,PublicKeyToken=31bf3856ad364e35, 可重定向=是'
堆栈跟踪表明它是在第一次调用 PCL 时,如果是如上所述的类型加载失败,则这是有意义的。
如果我删除对 PCL 程序集的引用,然后将关键类文件添加到两个程序集,则一切正常,但我想避免这种代码重复......所以问题是:为什么会发生这种情况?如何配置 PCL 使其按书面方式运行?
编辑:更多信息...我的 PCL 使用 XmlSerializer,位于桌面上的 System.Xml.dll 中的东西,以及Silverlight中的System.Xml.Serialization.xml...在完整的桌面框架下不存在的程序集...所以这个失败是有一定道理的,只有在PCL世界中,其中一些程序集/类在 在这种情况下, XmlSerializer
实际上位于 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile2\System.Xml.Serialization.dll(由 PCL 引用)...作为测试,我向 Web 项目添加了相同的引用...但是在网络项目运行时,它失败并出现黄屏死机,说明:
无法加载文件或程序集“System.Xml.Serialization”或其中之一 它的依赖项。找到的程序集的清单定义不 匹配装配参考。 (HRESULT 异常:0x80131040)
I have 3 assemblies, a WP7 app (targeting 7.0), a Web Services project (running 4.0), and a Portable Class Library (built from the template & targeting WP7, SL4 & .NET 4.0) which contains a common type used between the first two.
When run locally (in IIS Express) things work just fine, however when run against a deployed instance of the Web Services assembly (on a remote IIS server I have little control of) fails with the following exception:
System.IO.FileNotFoundException: Could not load file or assembly
'System.Xml.Serialization, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. The
system cannot find the file specified. File name:
'System.Xml.Serialization, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' ---> System.IO.FileNotFoundException:
Could not load file or assembly 'System.Xml.Serialization,
Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,
Retargetable=Yes' or one of its dependencies. The system cannot find
the file specified. File name: 'System.Xml.Serialization,
Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,
Retargetable=Yes'
The stacktrace indicates that it is on the first call into the PCL, which would make sense if it's a type load failure like above.
If I remove the reference to the PCL assembly and then add the key class file to both assemblies, things work fine, however I want to avoid this kind of code duplication... so the question is: Why is this happening? How can I configure the PCL to function as written?
EDIT: A little more information... my PCL uses XmlSerializer, something that lives in System.Xml.dll on the desktop, and in System.Xml.Serialization.xml in Silverlight... an assembly that doesn't exist under the full desktop framework... so this failure makes some sense, only in the PCL world, some of these assemblies/classes are broken out on their own
In this case, XmlSerializer actually lives in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile2\System.Xml.Serialization.dll (which is referenced by the PCL)... as a test I added the same reference to the Web Project... however at runtime of the web project, it fails with yellow screen of death stating that:
Could not load file or assembly 'System.Xml.Serialization' or one of
its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在远程服务器上安装KB2468871。它是一个已推送到大多数客户端计算机的 GDR - 但是,服务器需要选择它(它们通常不会自动安装更新)。
You will need to install KB2468871 on the remote server. It's a GDR that has been pushed to most client machines - however, servers will need to opt into it (they typically don't automatically install updates).