c# - Span<T> 和不在 .NET Native UWP 应用程序中工作的 friend

标签 c# uwp .net-native system.memory

重现步骤:

  1. 打开带有最新更新的 Visual Studio 2017。
  2. 在 10240 中创建一个 UWP 项目目标(这不是强制性的,它在所有构建中都被破坏)
  3. 从 nuget 包安装 System.Memory(单击包含预发布)
  4. 将这段代码复制粘贴到 MainPage.cs 中

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
       void Recursive(ReadOnlySpan<char> param)
       {
           if (param.Length == 0) return;
    
           tx1.Text += Environment.NewLine;
    
           tx1.Text += new string(param.ToArray());
           Recursive(param.Slice(1));
       }
    
       ReadOnlySpan<char> mySpan = "Why things are always broken in Visual Studio".AsSpan();
    
       Recursive(mySpan);
    }
    
  5. 复制粘贴到 MainPage.xaml

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
       <TextBlock x:Name="tx1" HorizontalAlignment="Left"   FontSize="48" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
    </Grid>
    
  6. 从调试切换到发布 x64 并确保“使用 .Net Native 工具链编译”。

  7. 点击播放。

  8. 收到此错误:

------ Build started: Project: App12, Configuration: Release x64 ------
App12 c:\Users\myuser\documents\visual studio 2017\Projects\App12\App12\bin\x64\Release\App12.exe
Processing application code
C:\Users\myuser.nuget\packages\microsoft.net.native.compiler\1.7.3\tools\Microsoft.NetNative.targets(697,5): error : Internal compiler error: Object reference not set to an instance of an object.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========

我做错了什么?这适用于没有 .NET Native 的调试和发布。谢谢。

最佳答案

System.Memory is in prerelease status and doesn't work yet with .NET Native. The next version of .NET Native compiler will have support for this.

https://github.com/dotnet/corert/issues/5725

关于c# - Span<T> 和不在 .NET Native UWP 应用程序中工作的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49900009/

相关文章:

c# - 使用 DataContext 在 Sharepoint Webpart 上抛出 401 未经授权的异常

ios - 如何启用滑动手势以在 Xamarin 表单 UWP 中引入母版页?

c# - UWP Entity Framework Core SQLITE 在 Release模式下崩溃

compiler-errors - 已添加具有相同 key 的项目 .Net 原生工具链

c# - 使用命名参数动态调用方法

c# - 尝试优化 linq 查询

c# - WebClient 强制超时

c# - 转换为计算/绝对位置

azure - 如何将遥测数据输入到 Windows 10 UWP 应用程序中?

c# - 如何在 WinForm 和 C# (Visual Studio 2015) 中使用 .Net Native?