After scratching my head for most of the day, I came across a very strange problem with .NET code compiled using .NET Native (used for Windows UWP applications).
The following code works fine in any .NET runtime, including Mono, Xamarin, etc.:
public class ABC {}
var constr = typeof(ABC).GetTypeInfo().DeclaredConstructors.First();
var abc = (ABC) constr?.Invoke(new object[0]);
On Windows UWP with the main .NET assembly, code throws an exception of type NotImplementedException
However, when the null distribution operator is deleted, it works fine on the .NET Native:
public class ABC {}
var constr = typeof(ABC).GetTypeInfo().DeclaredConstructors.First();
var abc1 = (ABC) constr.Invoke(new object[0]);
var abc2 = (ABC) constr?.Invoke(new object[0]);
The line in the stack trace where the exception occurs is:
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
in f:\dd\ndp\fxcore\CoreRT\src\System.Private.Reflection\src\System\Reflection\ConstructorInfo.cs:line 41
It smells like a compiler or runtime error . What's going on here? Did I miss something?