Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompiled Sources only show "throw null" for every .NET Framework class

I have

  • installed Visual Studio Community 2019, version 16.3.3 (including "ASP.NET and Web development" and ".NET Core cross-platform development")
  • and have checked "Enable Navigation to decompiled Sources",
  • and created a new ASP.NET Core Web Application (.NET Core 3.0.0)

but when I then look at e.g. the decompiled source for any referenced class in the .NET framework e.g. System.Console or for Microsoft.AspNetCore.Builder (or almost any other type), all I can see for every method's body is throw null (I showed an extract below)

I have read this question (update: and the answer to the question it was a duplicate to), but there only one class had this problem (because it was added in an incremental update). For me, this problem applies to every class in the .NET framework. What am I doing wrong? Is this expected behaviour and I should use something like dotPeek? Can I use a symbols server instead of decompiled sources? (Forgive my ignorance, I'm really new to C#... and the .NET world)

region Assembly System.Console, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.0.0\ref\netcoreapp3.0\System.Console.dll
// Decompiled with ICSharpCode.Decompiler 4.0.0.4521
#endregion

using System.IO;
using System.Text;
namespace System
{

// Summary:
// .... 
    public static ConsoleColor BackgroundColor
    {
        get
        {
            throw null;
        }
        set
        {
        }
    }

    //
    // Summary:
    //...
    public static int BufferHeight
    {
        get
        {
            throw null;
        }
        set
        {
        }
    }
    ...
like image 891
z_eb Avatar asked Dec 10 '25 02:12

z_eb


1 Answers

Have you tried it with ILSpy?

You can use it standalone (free version here: https://github.com/icsharpcode/ILSpy), but If you have LinqPad, then ILSpy is included (I think in the paid version).

Try it the following way:

  1. Create a sample program with 1 line you like to inspect:

    void Main()
    {
        System.Console.Clear();
    }
    
  2. With the mouse pointer, set the cursor on "Clear()" and then press F12.

  3. ILSpy opens showing the method you set the cursor on:

     // System.Console
     public static void Clear()
     {
        ConsolePal.Clear();
     }
    
  4. On the left side you can drill down into further into decompiled classes, e.g.

     internal static class ConsolePal
     {
         [Flags]
         internal enum ControlKeyState
         {
                     RightAltPressed = 0x1,
                     LeftAltPressed = 0x2,
                     RightCtrlPressed = 0x4,
                     LeftCtrlPressed = 0x8,
                     ShiftPressed = 0x10,
                     NumLockOn = 0x20,
                     ScrollLockOn = 0x40,
                     CapsLockOn = 0x80,
                     EnhancedKey = 0x100
     }
    
     private sealed class WindowsConsoleStream : ConsoleStream
     {
         private readonly bool _isPipe;
    
         private IntPtr _handle;
     // ...
    

NOTE: As an alternative to LinqPad, Visual Studio 2022 ships also with decompilation support for F12 enabled by default.

like image 127
Matt Avatar answered Dec 11 '25 15:12

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!