eine Konsole app erstellen zu reproduzieren:Sieht es für Sie wie ein C# Bug aus?
struct Test
{
public static readonly Test? Null = null;
}
class Program
{
static void Main(string[] args)
{
var t = Test.Null;
}
}
Es ist übersetzbar, aber wir werden die folgenden während der Laufzeit haben:
Eine nicht behandelte Ausnahme des Typs ‚System.TypeLoadException‘ in mscorlib aufgetreten .dll. Weitere Informationen: Der Typ 'ConsoleApplication17.Test' konnte nicht von der Assembly 'ConsoleApplication17, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null' geladen werden.
Dieser Ansatz löst das Problem:
struct Test
{
public static Test? Null => null;
}