ILSpy icon indicating copy to clipboard operation
ILSpy copied to clipboard

Weird cast

Open CreateAndInject opened this issue 1 year ago • 4 comments

Is the same issue as https://github.com/icsharpcode/ILSpy/issues/3011?

image

CreateAndInject avatar Aug 04 '24 10:08 CreateAndInject

Hard to say without taking a look at the IL...

siegfriedpammer avatar Aug 04 '24 17:08 siegfriedpammer

Hard to say without taking a look at the IL...

@siegfriedpammer Check it : test.zip

CreateAndInject avatar Aug 04 '24 17:08 CreateAndInject

image

Yes, in this assembly the code is trying to assign an array of type System.Byte from mscorlib v2 to a variable of type array of type System.Byte from mscorlib v4. This causes these weird casts.

siegfriedpammer avatar Aug 04 '24 18:08 siegfriedpammer

image image

How about those Unsafe.As? Is also the same issue?

CreateAndInject avatar Aug 04 '24 18:08 CreateAndInject

@dgrunwald do you think it would make sense to do "unification" of well-known/special types in the type-system?

siegfriedpammer avatar Oct 14 '24 12:10 siegfriedpammer

I think this makes more sense as a job for the assembly resolver -- there shouldn't be multiple mscorlibs in the same compilation. If we let both assemblyrefs resolve to the newer mscorlib version, then the typerefs will also resolve to the same type and the casts are avoided.

dgrunwald avatar Oct 16 '24 00:10 dgrunwald