5

重现步骤:

  1. 打开带有最新更新的 Visual Studio 2017。
  2. 在 10240 中创建一个 UWP 项目(这不是强制性的,它在所有版本中都已损坏)
  3. System.Memory从 nuget 包安装(单击包含预发行版)
  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. 从 Debug 切换到 Release x64 并确保“使用 .Net Native 工具链编译”。

  7. 单击播放。

  8. 收到此错误:

------ 构建开始:项目:App12,配置:Release x64 ------
App12 c:\Users\myuser\documents\visual studio 2017\Projects\App12\App12\bin\x64\Release\App12 .exe
处理应用程序代码
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设置为对象的实例。
========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========
========= 部署:0成功,0失败,0跳过==========

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

4

1 回答 1

3

System.Memory 处于预发布状态,尚不适用于 .NET Native。.NET Native 编译器的下一版本将支持此功能。

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

于 2018-04-18T14:39:49.507 回答