C# – Hide a method from the stack trace

When you want to exclude a method from showing up in the stack trace, you can apply the StackTraceHidden attribute to the method: Note: This attribute was added in .NET 6. You can apply StackTraceHidden to a class to hide all of its methods from the stack trace: Use StackTraceHidden with throw helper methods StackTraceHidden … Read more

C# – SecurityException when writing to the Windows Event Log

Problem When your application tries to write to the Windows Event Log, you get the following exception: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. … Read more

Starting the Visual Studio debugger when Attach to Process doesn’t work

Problem You’re trying to debug a program with Visual Studio but Attach to Process does not work. Most likely you’re loading your code through some third-party process (like Excel), and when you try to use Attach to Process it simply doesn’t work. Solution Instead of trying to use Attach to Process, you can launch a … Read more