Node script for syntax highlighting

I decided to switch my blog to use highlightjs instead of the mixture of my own library and ColorCode. I still wanted everything to rendered statically though so I decided to use highlight.js as it already offered instructions on how to use the library from node.

Read More

Enum Extension Methods

Did you know you can create extension methods for enums?

Read More

Disable C# null checks for a field or property

January 02, 2020 .net c# nrt nullable

The new nullable reference types in C# are great but sometimes you might need to disable it for a single field or property. You can do that by assigning the value to null and using the ! operator.

Read More

Use nameof() to set a string variable to its name

December 17, 2019 .net c#

This is one of those things that should have just been obvious to me but once I saw it I wondered why I had never thought to use it myself. nameof() can be used when declaring a variable to set the value of the variable to the name of the variable:

public const string MyVariable1 = nameof(MyVariable1);

public static void Main()
{
    Console.WriteLine(MyVariable1);
}
Read More

Dynamically loaded DLL thows AccessViolationException on first function call

October 22, 2019 .net c#

In my library GLESDotNet I load the libegl.dll and libglesv2.dll DLLs dynamically via the Win32 functions LoadLibrary and GetProcAddress. I already had everything working via DLLImport but I wanted to be able to load the DLLs from different subdirectories depending on the architecture.

For the first test I only loaded the libegl.dll DLL before moving on to the libglesv2.dll. I made the classic programmer mistake of changing too much at one time. The first call to any function in libegl.dll resulted in an AccessViolationException. I couldn't figure out what was going wrong so I decided to revert my changes and try again.

I noticed that when the DLLs were in the same directory the AccessViolationException went away. Changing the working directory to the directory of the DLLs also solved the problem once the DLLs were placed in subdirectories again. This led me to believe that loading libegl.dll must be implicitly loading libglesv2.dll. Loading libglesv2.dll via LoadLibrary along with libegl.dll solved the problem.