icsharpcode / ILSpy

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

Incorrect decompilation #643

Closed jbrekelmans closed 7 years ago

jbrekelmans commented 9 years ago

ILSpy information

Version 2.3.1.1855 Running on Windows 10 (this probably doesn't matter)

Method within mscorlib.dll (v4.0.0.0, see next section)

Qualified member name: System.Security.AccessControl.Privilege.TlsContents..ctor

Error description

The first finally block decompiles to: if (flag2) { object obj; Monitor.Exit(obj); } Obviously this is incorrect since an unassigned local variable is used.

mscorlib.dll version

// C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll // mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // Global type: // Architecture: x86 // Runtime: .NET 4.0 // ... [assembly: AssemblyVersion("4.0.0.0")] // ... [assembly: AssemblyDefaultAlias("mscorlib.dll")] // ... [assembly: AssemblyDescription("mscorlib.dll")] [assembly: AssemblyFileVersion("4.6.79.0")] [assembly: AssemblyInformationalVersion("4.6.79.0")] [assembly: AssemblyKeyFile("f:\dd\tools\devdiv\EcmaPublicKey.snk")] [assembly: AssemblyProduct("Microsoft® .NET Framework")] [assembly: AssemblySignatureKey("002400000c800000140100000602000000240000525341310008000001000100613399aff18ef1a2c2514a273a42d9042b72321f1757102df9ebada69923e2738406c21e5b801552ab8d200a65a235e001ac9adc25f2d811eb09496a4c6a59d4619589c69f5baf0c4179a47311d92555cd006acc8b5959f2bd6e10e360c34537a1d266da8085856583c85d81da7f3ec01ed9564c58d93d713cd0172c8e23a10f0239b80c96b07736f5d8b022542a4e74251a5f432824318b3539a5a087f8e53d2f135f9ca47f3bb2e10aff0af0849504fb7cea3ff192dc8de0edad64c68efde34c56d302ad55fd6e80f302d5efcdeae953658d3452561b5f36c542efdbdd9f888538d374cef106acf7d93a4445c3c73cd911f0571aaf3d54da12b11ddec375b3", "a5a866e1ee186f807668209f3b11236ace5e21f117803a3143abb126dd035d7d2f876b6938aaf2ee3414d5420d753621400db44a49c486ce134300a2106adb6bdb433590fef8ad5c43cba82290dc49530effd86523d9483c00f458af46890036b0e2c61d077d7fbac467a506eba29e467a87198b053c749aa2a4d2840c784e6d")] [assembly: AssemblyTitle("mscorlib.dll")] [assembly: SatelliteContractVersion("4.0.0.0")] // ... [assembly: ComCompatibleVersion(1, 0, 3300, 0)] // ... [assembly: Guid("BED7F4EA-1A96-11d2-8F08-00A0C9A6186D")] [assembly: TypeLibVersion(2, 4)] // ...

weltkante commented 9 years ago

AssemblyFileVersion("4.6.79.0")

Thats .NET 4.6 which is compiled via Roslyn and not supported by ILSpy. I have some changes in my fork which fix the largest issues but it is not complete, and it doesn't cover all of the locking constructs either (it does fix some though).

As far as I know there are no plans to add complete Roslyn support, so without external contribution you shouldn't expect ILSpy to emit (re)compilable code for Roslyn based assemblies anytime soon.

dgrunwald commented 7 years ago

This was fixed in the new decompiler engine (which just landed on the master branch) -- the Roslyn lock() pattern is now supported.