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

1

6

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.

Genome answered 18/4, 2018 at 12:41 Comment(5)
"Span<T> and friends", how did you get to that conclusion? Does it compile if you remove those references? What about without recursion?Enterpriser
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.Genome
Does this happen also with e.g. char[] type?Ultrasound
If I remove the Span<T> code and add char[] is fine. So the problem is the System.Memory Span<T> and friends thingy.Genome
"Internal compiler error" message suggests that you might have better luck posting this to .net native issue tracker.Kan
G
3

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

Genome answered 18/4, 2018 at 14:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.