Home

Why LINQPad generate different IL and C#1.0 result from sharplab.io

Hi,
I just tried the LINQPad tool, I tried to compare it to sharplab and i found that

  1. [JIT Asm] in sharplap = [X64 / x32 / ....] in LINQPad,

  2. and the [IL] section in LINQPad is only the body of the generated method in sharpLap [IL]

  • So i have two questions
  1. is there any way to get the full generated IL
  2. is there any way to get the full generated C#1.0 code, [Lowered Code] like sharplap do.

thankyou.

Comments

  • Press Alt+Shift+R - this will open the code in ILSpy and then you see the surrounding IL as well as choose the exact version of C# you want it lowered to.

  • edited February 2022

    Thank you,

    But this does not seems to work correctly

    for example - for this code

    class Program{
    public static void Main(){
    Console.WriteLine("ASDSAD");
    using var cross = new Runner();
    }
    }

    class Runner : IDisposable
    {
    public void Dispose()
    {
    throw new NotImplementedException();
    }
    }

    • SharpLap result in

    using System;
    using System.Diagnostics;
    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Security;
    using System.Security.Permissions;

    [assembly: CompilationRelaxations(8)]
    [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
    [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
    [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
    [assembly: AssemblyVersion("0.0.0.0")]
    [module: UnverifiableCode]
    internal class Program
    {
    public static void Main()
    {
    Console.WriteLine("ASDSAD");
    Runner runner = new Runner();
    try
    {
    }
    finally
    {
    if (runner != null)
    {
    ((IDisposable)runner).Dispose();
    }
    }
    }
    }
    internal class Runner : IDisposable
    {
    public void Dispose()
    {
    throw new NotImplementedException();
    }
    }

    this is actually, the lowered -rewritten- c#, and this is a phase in the compilation process

    Now in LinqPad -> ILViewer - with C# v1.0 set

    // Program
    using System;

    internal class Program
    {
    public static void Main()
    {
    Console.WriteLine("ASDSAD");
    using (new Runner())
    {
    }
    }
    }

    so I think that IlSpay is not aware of the lowering phase of the .net compiler.

  • I presume you are talking about ILSpy using the 'using statement'.
    That is perfectly valid C# 1.0 code , but if you don't want ILSpy to use it, you can disable it under
    View/Options/Decompiler C# 1.0 / Detect using statements

  • @sgmoore thank you very much, this is what I need.

    but can I force these roles in LinqPad itself, to not open ILSpay?

Sign In or Register to comment.