为什么在 OS X 上的 Xamarin Studio 中会出现以下错误,但在 Visual Studio 中不会出现以下错误?

Why would the following errors occur in Xamarin Studio on OS X but not in Visual Studio?

我试图理解为什么在 OS X 上 运行 在 Xamarin Studio 5.9.1(内部版本 3)中进行测试时出现以下错误。


System.IO.FileNotFoundException : Could not load file or assembly 'System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.


System.TypeLoadException : A type load exception has occurred.


所有项目都成功构建并且相同的测试 运行 在 Visual Studio 和 Windows 使用相同的解决方案都很好。

am 在 OS X 上构建测试项目时看到警告,尽管已经安装并添加了引用。

All projects referencing MyProject.fsproj must install nuget package Microsoft.Bcl.Build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317569.

不同的平台(Android、iOS、桌面)有不同的 System.Net.Http.dll 二进制文件 - 从相同的源编译,但每个版本都引用 mscorlib.dll(和其他base-class 库)来自其构建平台。

当您在应用程序中使用它时,这不是问题 - Xamarin Studio 会自动为您选择正确的版本 - 但您不能在便携式 Class 库中使用它。

Microsoft 最初将 HttpClient 实现为 .NET 4.5 的一部分,但随后发布了它的可移植版本(具有 Windows-only 许可证)。如果我理解正确,那么这与 .NET 4.5 中的 API 基本相同,加上一些小的添加(我认为他们添加了 gzip 压缩,而 Mono 的版本目前没有)。

对于 Xamarin / Mono,要创建该库的开源版本,我们需要做的就是获取现有源代码并根据可移植配置文件编译它们。我还没有尝试过,但这可能就像编辑 .csproj 文件并替换 .

一样简单

也建议您安装HttpClient NuGet package System.Net.Http.HttpClient 可直接从最新版本的 Xamarin 获得。

只需从 Xamarin Studio 检查更新 ;-)

我仍然不知道为什么 Xamarin 的行为与 Visual Studio 不同,但根本原因是测试项目的目标是 .Net 4.5,而主项目的目标是 .Net 4.0

感谢@7sharp9 的帮助。