重现步骤:
- 打开带有最新更新的 Visual Studio 2017。
- 在 10240 中创建一个 UWP 项目目标(这不是强制性的,它在所有构建中都被破坏)
- 从 nuget 包安装
System.Memory
(单击包含预发布) 将这段代码复制粘贴到 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); }
复制粘贴到 MainPage.xaml
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <TextBlock x:Name="tx1" HorizontalAlignment="Left" FontSize="48" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> </Grid>
从调试切换到发布 x64 并确保“使用 .Net Native 工具链编译”。
点击播放。
收到此错误:
------ 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.
关于c# - Span<T> 和不在 .NET Native UWP 应用程序中工作的 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49900009/