Skip to content

Instantly share code, notes, and snippets.

@premun
Last active September 20, 2023 19:59
Show Gist options
  • Save premun/c27b37d58beb9f49cce4026299019de8 to your computer and use it in GitHub Desktop.
Save premun/c27b37d58beb9f49cce4026299019de8 to your computer and use it in GitHub Desktop.
`dotnet/dotnet` experiments

ℹ️ Instructions for https://twitter.com/premun_/status/1626560566469791746

Using Codespaces

  1. Create a Codespace from https://github.com/dotnet/dotnet image
  2. Change the NullReferenceException.cs file
    code /workspaces/dotnet/src/runtime/src/libraries/System.Private.CoreLib/src/System/NullReferenceException.cs
  3. Build the .NET SDK (~45 minutes)
    cd /workspaces/dotnet && ./prep.sh && ./build.sh --online
  4. Unpack the SDK
    mkdir /workspaces/.dotnet && tar -zxf artifacts/x64/Release/dotnet-sdk-* -C /workspaces/.dotnet
  5. Create a new project:
    mkdir /workspaces/foo && cd /workspaces/foo && /workspaces/.dotnet/dotnet new console
  6. Change Program.cs to throw an NRE
    code Program.cs
    You can put something like Console.WriteLine(((string?)null)!.Length);
  7. Run it /workspaces/.dotnet/dotnet run
    🔥🔥🔥

Using Docker

  1. Run the container:
    docker run --rm -itv vmr:/vmr -w /vmr mcr.microsoft.com/dotnet-buildtools/prereqs:fedora-36
  2. Clone the monorepo
    git clone https://github.com/dotnet/dotnet .
  3. Change the NullReferenceException.cs file
    vi /vmr/src/runtime/src/libraries/System.Private.CoreLib/src/System/NullReferenceException.cs
  4. Build the .NET SDK
    ./prep.sh && ./build.sh --online --clean-while-building
  5. Unpack the SDK
    mkdir -p $HOME/.dotnet && tar -zxf artifacts/x64/Release/dotnet-sdk-* -C $HOME/.dotnet
  6. Create a new project:
    mkdir $HOME/foo && cd $HOME/foo && $HOME/.dotnet/dotnet new console
  7. Change Program.cs to throw an NRE
    echo 'Console.WriteLine(((string?)null)!.Length);' > Program.cs
  8. Run it $HOME/.dotnet/dotnet run
    🔥🔥🔥
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment