Deleting GitHub History

To delete all the history of your GitHub repository:

  1. Checkout your code: git checkout –orphan latest_branch
  2. Add the files: git add -A
  3. Commit the changes: git commit -am “commit message”
  4. Delete the branch: git branch -D master
  5. Rename the current branch to master: git branch -m master
  6. Finally, force update your repository: git push -f origin master

All your history will be lost. This process is very useful if credentials or commercial secrets accidently get submitted and need to be removed without trace.

The type initializer for ‘CLASS_NAME’ threw an exception. InvalidOperationException: No process is associated with this object.

In the process of writing a .NET 5 console application to monitor HTTP(S) traffic, I encountered the following issue:

The type initializer for ‘CLASS_NAME’ threw an exception. InvalidOperationException: No process is associated with this object.

The problem manifests itself when the object being instantiated is marked as static when it should not be. By removing the static keyword, and instantiating the object as an instance variable, the exception goes away.

Posted in C#

Please select a valid symbol to be moved.

In a Visual Studio database project, you open a SQL file and right-click on the name of the item, and then select Move to Schema. But you are presented with a dialog that states: “Please select a valid symbol to be moved.”

The problem is to do with the build setting for the file. Change the build setting for the file to Build and Do not copy, and after that, you will be presented with the Move to Schema dialog.

Clean Code in C#

I am pleased to announce that I am the author of Clean Code in C#. A lot of effort has gone into this book to help you become a better programmer in C#. The book starts off by looking at bad and good code and the need to have good coding standards such as DRY, KISS, SOLID, and YAGNI. Then we move on to look at the process and importance of code reviews for maintaining clean code before it is submitted to version control. After this, we discuss classes, objects, and data structures including topics such as The Law of Demeter, immutable objects and data structures, and only exposing what needs to be exposed and hiding everything else.

We then move on to look at writing clean functions in C# by looking at functional programming, reducing the number of parameters in method calls, and avoiding duplication. Following on from this, we discuss exception handling and consider checked and unchecked exceptions, avoiding the NullPointerException, business rule exceptions, and building your own custom exceptions.

Unit testing and the fail-pass-refactor test-driven development methodology are then discussed, followed by a look into end-to-end system testing by writing three console applications that provide a good practical demonstration of this. Once we have covered testing, we move on to discuss threading and concurrency. We start by looking at the threading lifecycle and then move onto advanced parallel and concurrency issues and how to prevent them with code examples.

Next, we look at language-agnostic API design using RAML, and then build a C# API from the RAML specification. And we use Swagger to document our API. This is followed by looking at how to secure APIs with API keys and Azure Key Vault. We then move on to address cross-cutting concerns and how to use the PostSharp Aspect Framework, and even how to develop our own aspects. Then we look at various tools to help us refactor our code such as code analysis, code metrics, Resharper, dotTrace, and JustDecompile.

Finally, the last two chapters cover refactoring in detail. Chapter 13 helps you to identify code smells at the application, class, and method levels. And Chapter 14 helps you to refactor code by using design patterns. There are plenty of code examples and questions to enforce your learning, and the code is available on GitHub.

By the time you have read this book, you will understand what constitutes good and bad code, how to identify and refactor bad code to make it clean, how to design, implement, and document APIs,  and will have a fully functional working secured FinTech API.

To get the most out of this book, I recommend you download and investigate the source code. And I also recommend that you hand-code the source code in the book and complete all tasks, questions, and further reading. You can obtain the book from the following sources:

  1. Packt

If you encounter any books from Packt being made free for download on pirate websites, then please report the issue by sending an email to

.NET Application Encounters “Registry access not allowed.” exception

If you have a .NET application that accesses the registry, and on Windows 10, you receive the exception “Registry access not allowed.”, then update your applications configuration file as follows:

<?xml version=”1.0″?>
<asmv1:assembly manifestVersion=”1.0″ xmlns=”urn:schemas-microsoft-com:asm.v1″ xmlns:asmv1=”urn:schemas-microsoft-com:asm.v1″ xmlns:asmv2=”urn:schemas-microsoft-com:asm.v2″ xmlns:xsi=””&gt;
   <assemblyIdentity version=”″ name=”” />
   <trustInfo xmlns=”urn:schemas-microsoft-com:asm.v2″>
         <requestedPrivileges xmlns=”urn:schemas-microsoft-com:asm.v3″>
            <requestedExecutionLevel level=”requireAdministrator” uiAccess=”false” />
You may also need to configure the shortcut for the executable to run as “Administrator”.

SQL Server Browser Service Fails To Start

When the SQL Server Browser Service fails to start, check your Windows Application event log. You may see the following critical entry:

The SQL Server Browser service was unable to establish SQL instance and connectivity discovery.

If you see this entry, then this blog post has a solution that works to solve the issue:

The issue is down to SSRP being enabled in the registry, and is solved by setting its value to 0.

VSCODE Terminal Does Not Recognise Command

If you run the terminal in VSCode on Windows, and the command is not recognised, make sure that the Path environment variable includes the following path: C:\Users\\AppData\Roaming\npm. Also, make sure that this entry is at the beginning of the list because your path list can be too big for the VSCode Terminal to handle. This can be determined by typing echo %PATH% in your terminal window, and comparing it with the external cmd.exe window.

Change Docker Image Location on Windows

By default Docker sets up MobyLinuxVM and downloads and installs docker image on your C:\ drive. For most people this is not ideal, as this is our main application drive and can be limited in space. Especially if you are using Docker on a laptop with a small hard drive. So you will probably want to use an different drive to your C:\ drive.

It is a very straight forward task to perform.

First of all, you need to stop your docker containers using the docker stop [Container Name] command. For a list of all your docker images, run the command: docker images –all.

Then type “Hyper-V Manager in the taskbar search box and run it. Select your PC in the left hand pane. Right-click on the correct virtual machine which by default is called MobyLinuxVM. Select “Turn Off”. Right-click on the Virtual Machine and select “Move”. Follow the on-screen prompts to move your VM.

Now open Docker Settings and select Daemon. Switch from Basic to Advanced. Edit the JSON so that it looks like:

“registry-mirrors”: [],
“insecure-registries”: [],
“debug”: true,
“experimental”: false,
“graph”: “G:\\DockerImages”

Click on Apply to apply your change. In the JSON above, the graph property is the location where your docker images will be placed by default from now on.

51GYZtbe1sL._SX404_BO1204203200_If you are new to Docker and would like to learn more on how to use Docker on Windows then you can buy the book Docker on Windows published by Packt.

Author Elton Stoneman guides you through getting started with docker on Windows, packaging and running applications as docker containers, developing dockerised .NET and .NET Core Applications, pushing and pulling images from docker registries, adopting container-first solution design, organising distributed solutions with Docker Compose, administering and monitoring dockerised solutions, understanding the security risks and benefits of docker, powering a continuous deployment pipeline with docker, debugging and instrumenting application containers, and guidance for implementing docker by containerising what you know.

Mebsuta – Eclectic Moods – New Album

I have released my first music album on Bandcamp. It is a mixture of music including classical, pop, and techno. You can listen here: The individual tracks can be bought as well as the album. My band name is Mebsuta after a star in Gemini, and the album is called Eclectic Moods.