Repository for presentation, Dive Into .NET Core GitHub Repository at TRINUG Meetup
- The CoreCLR on GitHub
- https://github.com/dotnet/coreclr
- This is the JIT and Garbage Collector
- The CoreFX on GitHub
- https://github.com/dotnet/corefx
- This is the Standard Library
-
Use the MS ReferenceSource site
-
They also mirror it to GitHub
- Use the search box in the upper-left corner when on the GitHub repository of interest. This searches the contents of the files.
- Use the Find Files feature, either press the button or press the 't' key on the page. This searches the names of the files only.
- These both are only searching the master branch, so it may have changes, e.g. a newer version of .NET than you are using.
- Either git clone the repository
- Or download the source code as a zip. CoreFX-master.zip is ~38 MB download.
Then use something like VS Code, https://code.visualstudio.com/ to search the cloned Git repository or the extracted zip file.
- For .NET Core 2 or later
- Disable Just My Code in Debugging\General settings.
- Enable Source Link support in Debugging. You must have VS 2017 15.3 or later.
- Enable the Microsoft Symbol Servers in Debugging\Symbols
- Step into .NET Core code, e.g. String.Join, List constructor.
- Or click farther up in the call stack when on a breakpoint.
- It will prompt you to download the raw source code file from the GitHub repository.
- Now that you have the source code file, you can set breakpoints in the .NET Core code.
- Copied from this Steve Gordon Blog, https://www.stevejgordon.co.uk/debugging-asp-net-core-2-source
- In you want to clean the downloaded files, go to C:\Users\[YourUserName]\AppData\Local\SourceServer and delete the subfolders.
- Yes, you can.
- In the .vscode\launch.json add
"justMyCode": false,
"symbolOptions": {
"searchMicrosoftSymbolServer": true
}
- Your compiled code, e.g. .dll and .exe only contain the generated IL, (https://en.wikipedia.org/wiki/Common_Intermediate_Language)
- Show how does the debugger point you at a source code file?
- The pdb contains a mapping from generated IL addresses to a mapping into the name of the class and the name of the method.
- The pdb optionally can include the original line number and original file name.
- The pdb can optionally contain a reference to how to locate the original source code (e.g. where on the filesystem the code was originally built from). Most recently, SourceLink embeds links to external servers when the source code can be downloaded from.
- The Visual Studio debugger allows you to turn on symbol servers. When this is done it will contact the symbol server as assemblies are loaded in attempt to locate .pdb files from the symbol server and download them to your local machine.
I couldn't get it to work
- Try https://referencesource.microsoft.com/setup.html
- http://www.symbolsource.org/Public/Home/VisualStudio
- It is a generic way for .NET packages to bundle their debug symbols and then point to the corresponding source code on GitHub or somewhere else.
- https://blog.nuget.org/20180827/Introducing-Source-Code-Link-for-NuGet-packages.html
- https://www.hanselman.com/blog/ExploringNETCoresSourceLinkSteppingIntoTheSourceCodeOfNuGetPackagesYouDontOwn.aspx
- https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink
- https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/nuget#symbol-packages
- See current source code providers here: https://github.com/dotnet/sourcelink
- We looked at List source code. https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Collections/Generic/List.cs
- We are did a .Select() followed .ToList() on an original list. That lead us to specialized SelectListIterator in https://github.com/dotnet/corefx/blob/master/src/System.Linq/src/System/Linq/Select.cs
- We looked at Random.Next() code, https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Random.cs
- We looked at the EmailAddressAttribute, https://github.com/dotnet/corefx/blob/master/src/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/EmailAddressAttribute.cs
- We also used the .NET reference source and looked at the prior implementation of EmailAddressAttribute, which used to use a RegEx.
- We also learned how to set a function breakpoint, see this blog https://blog.reyno.co.uk/debugging-asp-net-core-source-code/ for more details.
- We quickly looked at String, https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/String.cs
- We looked at ArgumentNullException and ArgumentException, https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/ArgumentNullException.cs
- Specifically we looked at https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/ArgumentException.cs to see how serialization of exception properties is done.
- We looked back at List, https://github.com/dotnet/corefx/blob/master/src/Common/src/CoreLib/System/Collections/Generic/List.cs to learn about the DebuggerDisplayAttribute.
- Specifically it's a feature you can use in your types, https://docs.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute?view=vs-2017