修复System.Core 2.0.5 FileLoadException,可移植库和Windows XP支持

Installing Windows XP to test

My buddy Greg and I are getting ready to launch our little side startup, and I was going through our product backlog. Our app consists of a global cloud service with Signalr, an iPhone app made with Xamarin tools, and a WPF app.

我的好友Greg和我已经准备好启动我们的小型副业,而我正在处理我们的产品积压。 我们的应用程序包括带有Signalr的全球云服务,使用Xamarin工具制作的iPhone应用程序和WPF应用程序。

One of the items in our Trello backlog was "Support Windows XP. Gasp!"

Trello待办事项中的一项是“支持Windows XP。加油!”

I hadn't given this item much thought, but I figure it was worth a few hours look. If it was easy, why not, right?

我没想过这个项目,但我认为值得几个小时的时间。 如果很容易,为什么不呢?

Our WPF desktop application was written for .NET 4.5, which isn't supported on Windows XP.  I want to my app to support as basic and mainstream a .NET 4 installation as possible.

我们的WPF桌面应用程序是为.NET 4.5编写的,Windows XP不支持。 我希望我的应用程序尽可能支持基本和主流的.NET 4安装。

Could I change my app to target .NET 4 directly? I use the new async and await features extensively.

我可以将我的应用程序直接定位为.NET 4吗? 我广泛使用了新的异步和等待功能。

Well, of course, I remembered Microsoft released the Async Targeting Pack (Microsoft.Bcl.Async) through NuGet to do just this. In fact, if I was targeting .NET 3.5 I could use Omer Mor's AsyncBridge for .NET 3.5, so it's good that I have choices.

好吧,当然,我记得微软通过NuGet发布了异步定位包(Microsoft.Bcl.Async)来完成此操作。 实际上,如果我的目标是.NET 3.5,则可以使用Omer Mor的.NET 3.5AsyncBridge ,因此我可以选择是一件好事。

I changed my project to target .NET 4, rather than 4.5, installed these NuGets, and recompiled. No problem, right?

我将项目更改为目标.NET 4(而不是4.5),安装了这些NuGet,然后重新编译。 没问题吧?

However, when I run my application on Windows XP it crashes immediately. Fortunately I have instrumented it with Raygun.io so all my crashes to to the cloud for analysis. It gives me this nice summary:

但是,当我在Windows XP上运行应用程序时,它立即崩溃。 幸运的是,我已经用Raygun.io对其进行了检测,因此我所有的崩溃都转移到了云中进行分析。 它给了我这个很好的总结:

raygun.io is amazing

Here's the important part:

这是重要的部分:

FileLoadException: Could not load file or assembly 
'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047)

That's weird, I'm using .NET 4 which includes System.Core version 4.0. I can confirm what's in the GAC (Global Assembly Cache) with this command at the command line. Remember, your computer isn't a black box.

太奇怪了,我正在使用包含System.Core 4.0版的.NET 4。 我可以在命令行中使用此命令来确认GAC(全局程序集缓存)中的内容。 请记住,您的计算机不是黑匣子

C:\>gacutil /l | find /i "system.core"
System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL
System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL

OK, so there isn't even a System.Core version 2.0.5 in the GAC. Turns out that System.Core 2.0.5 is the Portable Libraries version, meant to be used everywhere (that means, Silverlight, etc, everywhere) so they made the version number compatible.

好的,因此GAC中甚至没有System.Core版本2.0.5。 原来System.Core 2.0.5是Portable Libraries版本,可以在任何地方(即,Silverlight等)使用,因此它们使版本号兼容。

Because we're building our iPhone app with Xamarin tools and we anticipate supporting other platforms, we use a Portable Library to share code. But, it seems that support for Portable Libraries were enabled on .NET 4 vanilla by the KB2468871 update.

因为我们正在使用Xamarin工具构建我们的iPhone应用程序,并且我们期望支持其他平台,所以我们使用可移植库来共享代码。 但是,似乎通过KB2468871更新在.NET 4 vanilla上启用了对可移植库的支持。

I don't want to require any specific patch level or hotfixes. While this .NET 4 framework update was pushed to machines via Windows Update, for now I want to support the most basic install if I can. So if the issue is Portable Libraries (which I still want to use) then I'll want to bring those shared files in another way.

我不需要任何特定的补丁程序级别或修补程序。 尽管此.NET 4框架更新是通过Windows Update推送到计算机上的,但目前我希望支持最基本的安装。 因此,如果问题是可移植库(我仍想使用),那么我想以其他方式携带这些共享文件。

You can LINK source code in Visual Studio when you Add File by clicking the little dropdown and then Add as Link:

您可以在添加文件时在Visual Studio中链接源代码,方法是单击小下拉列表,然后单击添加为链接:

Adding source code as a Link within Visual Studio

Now my Messages.cs file is a link. See the little shortcut overlay in blue?

现在,我的Messages.cs文件是一个链接。 看到蓝色的小捷径覆盖物?

A linked file as a little overlay on the icon

I removed the project reference to the Portable Library for this WPF application and brought the code in this way. I'm still sharing core, but just not as a binary for this one application.

我删除了对该WPF应用程序的可移植库的项目引用,并以这种方式带来了代码。 我仍在共享核心,但不是该应用程序的二进制文件。

Recompile and redeploy and magically .NET 4 WPF application with async/await and MahApps.Metro styling starts up and runs wonderfully on this 12 year old OS with just .NET 4 installed.

带有async / await和MahApps的.NET 4 WPF应用程序可以重新编译和重新部署,并且具有魔力。Metro样式可以启动,并且可以在这只安装了.NET 4的12岁操作系统上完美运行。

For our application this means that my market just got opened up a little and now I can sell my product to the millions of pirated and forever unpatched Windows XP machines in the world. Which is a good thing.

对于我们的应用程序来说,这意味着我的市场刚刚打开了一点,现在我可以将我的产品卖给世界上数百万个盗版且永久未打补丁的Windows XP机器。 这是一件 好事

翻译自: https://www.hanselman.com/blog/fixing-systemcore-205-fileloadexception-portable-libraries-and-windows-xp-support

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值