Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it look like a C# bug for you? [duplicate]

Create a console app to reproduce:

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

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

It is compilable, but we will have the following at run time:

An unhandled exception of type 'System.TypeLoadException' occurred in mscorlib.dll. Additional information: Could not load type 'ConsoleApplication17.Test' from assembly 'ConsoleApplication17, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

This approach solves the problem:

struct Test
{
    public static Test? Null => null;
}
like image 886
Dmitry Nogin Avatar asked May 13 '16 01:05

Dmitry Nogin


People also ask

What color is the C wire usually?

The C, or common wire, provides smart thermostats with continual power. It's usually blue, but it may also be black, brown or purple. The O or orange wire connects to your heat pump (if applicable).

Is AC just cold?

Air Conditioning CompressorThe car's compressor does more than just cool the air before it passed through the car. You can use the a/c compressor while controlling the heat setting of the car to control the climate within.

Is the C wire positive or negative?

The "C" wire as most are naming it is the Common Wire, think of the common wire as the negative end of a battery, positive on one side negative on the other, you need to complete the circuit to make the device work .


1 Answers

This is known implementation limitation in CoreCLR - both the instance and static field layout is done together that results into this error. It is not easy to fix.

Source : Static fields should not contribute to cyclic struct layout #4049

like image 154
Xiaoy312 Avatar answered Sep 18 '22 12:09

Xiaoy312