5
votes

Steps to reproduce:

  1. Open Visual Studio 2017 with latest update.
  2. Create a UWP project targetin 10240 (this is not mandatory, it's broken in all builds)
  3. Install System.Memory from nuget packages (click include prerelease)
  4. Copy paste this code in to 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. Copy paste this to MainPage.xaml

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
       <TextBlock x:Name="tx1" HorizontalAlignment="Left"   FontSize="48" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
    </Grid>
    
  6. Switch from Debug to Release x64 and make sure "Compile with .Net Native tool chain".

  7. Click Play.

  8. Receive this error:

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

What I'm doing wrong? This works in Debug and release without .NET Native. Thanks.

1
"Span<T> and friends", how did you get to that conclusion? Does it compile if you remove those references? What about without recursion?Camilo Terevinto
If I remove System.Memory and this Span<T> code the app compiles in .Net Native. If you follow the steps, It won't compile. If I remove the recursive it doesn't work either. It's the nuget package.Fritjof Berggren
Does this happen also with e.g. char[] type?FCin
If I remove the Span<T> code and add char[] is fine. So the problem is the System.Memory Span<T> and friends thingy.Fritjof Berggren
"Internal compiler error" message suggests that you might have better luck posting this to .net native issue tracker.Evk

1 Answers

3
votes

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