2016-05-13 30 views
16

Creare una console app per riprodurre:Ti sembra un bug C# per te?

struct Test 
{ 
    public static readonly Test? Null = null; 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     var t = Test.Null; 
    } 
} 

E 'compilabile, ma avremo il seguente in fase di esecuzione:

un'eccezione non gestita di tipo 'System.TypeLoadException' si è verificato in mscorlib .dll. Ulteriori informazioni: Impossibile caricare il tipo "ConsoleApplication17.Test" dall'assembly "ConsoleApplication17, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null".

Questo approccio risolve il problema:

struct Test 
{ 
    public static Test? Null => null; 
} 

risposta