Span<T> 和不在 .NET Native UWP 应用程序中工作的朋友

Span<T> and friends not working in .NET Native UWP app

重现步骤:

  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 并确保 "Compile with .Net Native tool chain"。

  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.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