xamarin - 更新到 Visual Studio 2017 版本 15.8 预览版后,出现 "Can not resolve reference: ` System.Memory `"或 "Could not find ` System.Memory `"

标签 xamarin xamarin.ios xamarin.android

如果它可能对其他人有帮助,我将询问并回答这个关于从 Visual Studio 2017 版本 15.7 更新到版本 15.8 预览版后 Xamarin.Android 和 Xamarin.iOS 项目中可能出现的问题的小问题。

演示该问题的示例步骤

  1. 创建一个新的空白 Xamarin.Android 或 Xamarin.iOS 项目。
  2. 将 Microsoft.AspNetCore.SignalR.Client.Core 版本 1.0.0 NuGet 包添加到项目中。
  3. 使用项目中 NuGet 包中的类型。例如,将以下行添加到任何现有方法中:

    var connection = new Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder().Build();
    
  4. 对于 Xamarin.Android,尝试在调试配置中构建项目。对于 Xamarin.iOS,在 iPhone 模拟器上的调试配置中构建并运行应用程序。

Visual Studio 2017 版本 15.7 的结果

Xamarin.Android 应用和 Xamarin.iOS 应用均构建并运行,没有错误。

Visual Studio 2017 版本 15.8 预览版 4 的结果

对于 Xamarin.Android,构建失败:

Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.Connections.Abstractions`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.Connections.Abstractions`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Client.Core`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Client.Core`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Common`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Common`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Protocols.Json`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Protocols.Json`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.Extensions.Primitives`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.Extensions.Primitives`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `System.IO.Pipelines`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `System.IO.Pipelines`.

对于 Xamarin.iOS,应用程序在模拟器上成功启动,但调试输出显示应用程序在运行时无法找到 System.Memory:

Could not find `System.Memory` referenced by assembly `System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Client.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.Extensions.Primitives, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Protocols.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.

如何解决这些错误?后续,为什么我更新Visual Studio后会出现这些错误?

最佳答案

我使用 VS Entreprise 2017 版本 15.9.1

要解决我面临的问题(无法解析引用:System.Buffers,由System.Memory引用。请为添加NuGet包或程序集引用>System.Buffers,或删除对 System.Memory 的引用。), 我只是通过以下命令安装 System.Buffers 包:

安装包 System.Buffers -版本 4.5.0

https://www.nuget.org/packages/System.Buffers/

关于xamarin - 更新到 Visual Studio 2017 版本 15.8 预览版后,出现 "Can not resolve reference: ` System.Memory `"或 "Could not find ` System.Memory `",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296773/

相关文章:

logging - 在 xamarin studio 中激活日志输出

c# - 每天首次调用app时添加文字提示?

c# - Xamarin C# - 代码更改不会改变程序的工作

android - Xamarin Android : Cannot embed jna-4. 2.0.jar 进入Android Binding项目

android - 什么时候链接 "Sdk Assemblies Only"?

java - 有没有办法从 Windows 服务器生成 Realm.io 数据库?

xamarin - 如何使用 ViewModel 实现单击以选择

xamarin.ios - MonoDevelop:自动保存被询问很多次

c# - 使用 Microsoft Cognitive Speech + Websocket 的连续语音识别 - Xamarin

xamarin - 如何避免 Xamarin.Android 构建中的异常 "Sharing violation on path/android/gms/R.java and/android/gms/base.R.java"?