Steve Temple
Technical Director of Gibe Developer, Umbraco MVP/Certified Master/Unicore Team e-commerce expert, AI tinkerer
Advanced Debugging
Steve Temple
A little about me:
Steve Temple
Technical Director & co-founder of Gibe
Umbraco MVP x 2
One of the organisers of UmbracoSpark
Developer for over 25 years
Description: Nobody comes out of university with knowledge of Visual Studio's debugging features. Visual Studio has one of the most seamless debugging experiences for web development, but it's something you pick up on the job, not something you're taught. I'm going to demonstrate some of the more useful debugging features inside Visual Studio 2022.
Exception Details: System.Debugging.LackOfExperienceException: Gain more debugging experience to improve your development speed and capabilities.
Source Error:
[LackOfExperienceException (0x80008404): Gain more debugging experience to improve your development speed and capabilities] System.Debugging.Learn(ISkill skill, int visualStudioVersion) +124 System.Debugging.GetStarted() +279 System.Debugging.Talk(bool advanced) +56 Umbraco.Spark.Track2.Init() +10218 Umbraco.Spark.Start()
Version Information: UmbracoSpark v2023.2.1
Description:
If you're using IIS Express, Start Debugging (F5) will by default run in debug mode. Debug mode is slow, don't run in debug mode unless you need to debug.
Start without debugging (Ctrl+F5) when running an application, you can always attach to process after if you want to start.
Exception Details: System.Debugging.UneccessarilySlowException: Running in debug mode when you aren't debugging will slow your development times down
Source Error:
[UneccessarilySlowException (0x80008400): Running in debug mode when you aren't debugging will slow your development times down] *------------------------------------------------* | Spin up times of an Umbraco v11 site: | | -----------------------------------------------| | Debug mode: | 33s | | Non-debug mode: | 17s | | -----------------------------------------------| | Average page load time: | | -----------------------------------------------| | Debug mode: | 43ms | | Non-debug mode: | 24ms | *------------------------------------------------*
Version Information: UmbracoSpark v2023.2.1
Description: An incredibly useful debugging skill is to be able to interpret the error messages shown.
We've all seen these errors and they'll give you useful clues where to look.
Everyone has seen a NullReferenceException: Object reference not set to an instance of an object
Or how about 0x80004005, which is almost always some sort of permission issue
Exception Details: System.Debugging.RTFSTException: Read the flipping stack trace exception. Most errors you'll encounter can be diagnosed if you learn how to interpret the Stack Trace
Source Error:
[RTFSTException(0x80001400): Read the flipping stack trace exception.] System.Debugging.Comprehension.NotFound() +417 System.Debugging.StackTrace.Read(StackTrace stackTrace) +279 System.Web.Error() +56 System.Web.UI.Page.DeterminePostBackMode() +111 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint) +10218
Version Information: UmbracoSpark v2023.2.1
Description: Let's have a crack at running a site in debug mode, setting breakpoints and stepping through the code and see if we can fix some of the issues.
Source Error:
[LiveDemoException(0x80004005): The odds of a live demo working seamlessly is pretty remote.] System.Speaker.WhyAreYouMakingLifeHardForYourself() +347 System.Conference.Wifi() +417 System.InternetRequired() +279
Version Information: UmbracoSpark v2023.2.1
Description: There are some tools inside Visual Studio that make your debugging experience nicer.
We've already covered watches, but we can use DebuggerDisplayAttribute to make the display in that cleaner
We can also use Tracepoints to output debug display as we run the code
Source Error:
[DebuggerDisplay("Tweet by {Username} - {Text}")] public class Tweet { public string Text { get; set; } public string Username { get; set; } } Sample Tracepoint: $FUNCTION Found tweet by {usernames[0]} {comments[i]}
Version Information: UmbracoSpark v2023.2.1
Description: There are some little debugging features in Visual Studio that are little known and can be really helpful when you're working on a complex site.
Exception Details: HaveYouTriedException: Maybe some of these tools will make your life easier
Source Error:
[HaveYouTriedException(0x40005021): Maybe some of these tools will make your life easier BreakWhenVariableChanges() +21 ImmediateWindow() +45 SideEffectFreeFunctionEvaluation(", nse") +564 ImmediateWindowAtDesignTime() +2345 DebuggingIntoThirdParties() +457 StepBackwards() +236
Version Information: UmbracoSpark v2023.2.1
Description: Azure App Services has an option to remote debug the site, you can connect to a remote site and debug it straight from visual studio using the live traffic.
This does have some limitations, if you hit a breakpoint requests are paused, on production. Let's do some conditional breakpoints so it's only our requests that cause a breakpoint.
Getting this working can be a bit tricky if you're using a build pipeline as it will want the pdb to be an exact match to the dll.
You can get around this by downloading the .pdb file from the app service using the portal.
Exception Details: System.Debugging.RemoteDebuggingException: Multiple steps are involved and it can cause performance issues on the remote server if you're debugging directly on production.
Source Error:
ConditionalBreakpointSample: HttpContext.Request.QueryString.Value == "?debug"
Version Information: UmbracoSpark v2023.2.1
Description: Azure Application Insights can be configured to record Exceptions that occur on production App Services as snapshots
You need to have Application Insights setup and install and configure Microsoft.ApplicationInsights.SnapshotCollector
Exceptions will then be recorded in ApplicationInsights and you can download them and view the state of the application when an error occurred, allowing you to view variables etc.
Exception Details: System.Debugging.SnapshotDebuggerException: Quickly diagnose production exceptions with live data
Source Error:
[SnapshotDebuggerException(0x80080085): Quickly diagnose production exceptions with live data.] System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) +417 System.Web.HttpRequest.ValidateHttpValueCollection(HttpValueCollection collection, RequestValidationSource requestCollection) +279 System.Web.HttpRequest.get_QueryString() +56 System.Web.UI.Page.DeterminePostBackMode() +111 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +10218
Version Information: UmbracoSpark v2023.2.1
Thank you
By Steve Temple
Technical Director of Gibe Developer, Umbraco MVP/Certified Master/Unicore Team e-commerce expert, AI tinkerer