icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
21.45k stars 3.35k forks source link

Incorrect overloaded method in generated C# code #805

Closed mjmckp closed 7 years ago

mjmckp commented 7 years ago

(Issue copied from https://github.com/0xd4d/dnSpy/issues/429 - may already be fixed?)

The following bit of IL:

    IL_0011: ldfld class [mscorlib]System.IO.BinaryWriter MyClass::writer
    IL_0016: ldc.i4.3
    IL_0017: callvirt instance void [mscorlib]System.IO.BinaryWriter::Write(uint8)
    IL_001c: br IL_00fb

decompiles with dnSpy to the following bit of C#:

this.writer.Write(3);

The issue is that System.IO.BinaryWriter has an overloaded Write method, and the one that is being invoked in the IL is that for uint8, however the C# code as generated will invoke the Write method for int32.

This is quite a serious issue, as the de-compiled code compiles without any warnings, however the output of the program as written by the BinaryWriter will be incompatible with the original assembly.

siegfriedpammer commented 7 years ago

This was likely fixed in the new decompiler engine (which just landed on the master branch).