VS Code Bug – Interpolation and Commented Lines, Workaround

This is a quick post with a workaround to a bug in VS Code that occurs when you use string with @$ – the verbatim character and the interpolation characters.

If you have a piece of code that looks like this –

string text = @$"any text as long as there is a new line

Everything that comes after it will look commented out, like so –

This is a bit annoying because all coloring is lost below that /*.

You might not have hit this, but if start using Pulumi for IaC in AWS, you will because many permissions on resources often end with /*, or if you want to print some slashes and stars to the console.

Fortunately, there is a very easy workaround! Use $@ instead of @$.

string text = $@"any text as long as there is a new line

Much better!

The terminal shell path “dotnet” is a directory – Visual Studio Code

I have been using Visual Studio Code in Ubuntu Linux for a while, but it was not an easy process to get it working the first time.

I just got around to installing .NET Core 3.1 and hit a familiar problem –

The terminal shell path "dotnet" is a directory

This happens when I try to build inside VS Code using a build task, I point this out because building from a terminal inside VS Code works fine.

Here is the output –

> Executing task: dotnet build /home/bryan/dev/blog/SomeProject/SomeProject.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <

The terminal shell path "dotnet" is a directory

Terminal will be reused by tasks, press any key to close it.

If you google this you will find some suggested fixes but they didn’t work for me.

Here is what does work for me –

1. Install the SDKs to a directory NOT named dotnet, my SDK’s are in $HOME/msdotnet
2. Update your PATH to include this directory – PATH=$PATH:$HOME/msdotnet
3. Update your DOTNET_ROOT to this – DOTNET_ROOT=$HOME/msdotnet

That’s what works for me.

Whenever I need to install a new SDK I have do follow the manual steps outlined
here, making sure to unpack the SDK to $HOME/msdotnet.

Hope this works for you, please leave a comment if it does or even if it doesn’t.

dotnet new failing with Error: Invalid parameter(s)

If you are using Visual Studio Code and you want to add a new project to your workspace, the easiest thing to do is something like –

dotnet new xunit -f netcoreapp2.1

But you may get an error –

Error: Invalid parameter(s):
   -f netcoreapp2.1
      'netcoreapp2.1' is not a valid value for -f (Framework)

Here’s how to solve it.

Run –

dotnet --info

You will get a list of installed frameworks, your list will be different than mine –

This will show the list of frameworks installed 
.NET Core SDKs installed:
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.2.203 [C:\Program Files\dotnet\sdk]

Choose a version of the framework that you want, in my case I’ll use 2.1.503

Run this –

dotnet new globaljson --sdk-version 2.1.503

Now run –

dotnet new xunit -f netcoreapp2.1

and the new project will be created.

How to install .NET Framework 4.7 in Visual Studio 2017

Microsoft just released .NET Framework 4.7, but surprisingly it is not the easiest to install.

Here are the steps for Windows 10, as of this writing, it is not available for earlier versions for of Windows.

1. Install Windows 10 Creators Update

Go here https://www.microsoft.com/en-us/software-download/windows10, download and install. This will take a while and will reboot your computer a few times.

2. Install Visual Studio 2017 Updates

In Visual Studio, go to Tools -> Extensions and Updates, install any available updates.

(You might have the option here to install 4.7, see the image below in step 4.)

3. Open Visual Studio 2017 Installer

Use the Start Menu to search for the Visual Studio Installer.

In the installer, click Modify on the version of Visual Studio you have installed.

4. Install .NET framework 4.7

Click .NET desktop development.

On the right select .NET Framework 4.7 and finally install.

Locating and checking an executing DLL on a running web server or other application

Edit – even though the steps described below related to an example with IIS, you can use this technique for any running process, it’s just a matter of identifying the process id. In some cases you will not even need the process id, e.g. if all processes are using the same version of a DLL.


Figuring out what dll is actually executing on a running web server is no easy task; it’s not as simple as looking in the bin directory of the deployed application as the dlls are copied from there to a set of temporary directories within the windows systemroot.

I know of two ways of figuring this out, the first requires some code changes and the second does not.

I wrote some time ago about how to find which dll is really executing when running an application, it works just fine if you can alter the source code to include the snippet I proposed.

Clearly that is not a lot of use in a deployed application when you cannot change the code or even redeploy.

No code change needed

Here is the alternative, no code changes needed. The application I am interested in is called MyFancyApp, there are other applications running on the server too. Let’s say that the dll I am interested in is AutoMapper.dll, I need to verify that the running dll is really the version I expect.

1. Open a command prompt and navigate to %systemroot%\System32\inetsrv.
2. Execute appcmd list wp, this will show all the running application pools and the associated process ids. The output will look something like this –
find dll appcmd

You can see that MyFancyApp is running with process id of 1224.

Now switch to Process Explorer.

3. Open Process Explorer and hit CTRL-F, type in AutoMapper.dll. In the results PID 1224 is shown, in fact it will be there a few times. At this point the file location of the dll is visible.
find dll search

4. Double click one of the entries for PID 1224 where the Type is DLL.

5. In the lower pane of Process Explorer the AutoMapper.dll is selected and the version is shown, I had to right click on the lower pane and the version column to make it visible.

find dll results

That’s it. No redeploy, no code editing, no remote debugging. You now know for sure which dll is running and where to find it. If the dll is your own and you are concerned about what might be in the code you can open the file in dotpeek to decompile it.

Cached nuget packages causing you problems?

Short version
If you are having problems with nuget packages and think it might be related to local caching delete packages from these directories –


Long version
I was making nuget package, lets call it Foo, for my own use, not one that I was going to distribute publicly, but I was putting in on MyGet.

I had a few classes in it and after making the nuget package, I uploaded it to MyGet. I then switched to the Business solution and referenced this newly created nuget package.

After doing a little bit of work, I noticed that I had incorrectly made a class internal rather than public in the Foo nuget package.

No problem, back to the Foo solution where I was making the library, change the class to public, rebuild, and remake the nuget package. I didn’t want to increment the version number, so I left it at 1.0.0. On MyGet I deleted the old package and then uploaded the new one.

Here’s what I tried and didn’t work –

  • In the Business solution referencing the Foo nuget package, I uninstalled Foo and then reinstalled it.
  • But Visual Studio still reported that the class was inaccessible!
  • Uninstall and reinstall again, same problem!!
  • Delete the Foo directory from the packages directory beside the solution file, remove the Foo line from the packages.config. Reinstall Foo. Same problem!!!
  • Recomplie Foo, delete Foo from MyGet, reupload Foo to MyGet. Reinstall Foo. Still inaccessible!!!!
  • WTF!!!!!

And this is what works –

  • Download the Foo nuget package directly from MyGet and reference it directly. Success! There must be a local cache that Visual Studio is using!!!!!!

Yes there are, I found two –


Delete the offending nuget package; back in Visual Studio I can now successfully install the nuget package.

In general avoid using the same package version number when uploading a new package to MyGet.

Finding the Location of a Running Assembly in .Net

For many reasons you might want to know where a running assembly is located on your filesystem.

I had to do this once when I was compiling classes at runtime and had a dependency on EntityFramework. Another reason might be verifying which dll is actually being used in an application.

Here’s the simple method to perform the search –

    private string[] GetAssemblyLocation(string[] assemblyNames)
        string [] locations = new string[assemblyNames.Length];
        for (int loop = 0; loop <= assemblyNames.Length - 1; loop++)       
             locations[loop] = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && a.ManifestModule.Name == assemblyNames[loop]).Select(a => a.Location).FirstOrDefault();
        return locations;

And this is how you call it –

	string[] assemblyLocations = GetAssemblyLocation(new string[] { "System.Web.dll", "System.dll", "EntityFramework.dll" });

Saving enums as strings with Entity Framework

In September 2018 I wrote a new post explaining how to store enums as ints or strings with Entity Framework Core. It is a nicer solution than the one presented here.

Full source code here.

I hit a problem where I wanted to use Entity Framework to save the text value of an enum to the database rather than its numeric value. This is not possible with Entity Framework at the moment; there are a few hacky solutions out there. I add my own hacky solution here.

I have a Person class with an ID, name and gender; the gender is an enum with just male and female. I’d like to save “Male” or “Female” to the database instead of 1 or 2.

The enum is simple.

    public enum Gender
        Male = 1,
        Female = 2

The Person class makes use of Data Annotations to perform the correct mappings to the table. The Gender property is not mapped to the database while the GenderString is mapped as the column named Gender.

    public class Person 
        public int PersonID { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }

        public string GenderString
            get { return Gender.ToString(); }
            private set { Gender = value.ParseEnum<Gender>(); }

        public Gender Gender { get; set; }

I use an extension method to parse the text value of gender back into the enum.

    public static class StringExtensions
        public static T ParseEnum<T>(this string value)
            return (T)Enum.Parse(typeof(T), value, true);

Rows in the table will now have the string value of the enum rather than that number.


And when a person is loaded from the database the Gender enum is correctly populated.

The only drawback is that there is now a public property called Gender and GenderString on the Person class, but I have made the set of GenderString private to prevent accidental updating.

Full source code here.

Dotclear blog editing problem

The dotclear blogging engine has some issues when including pre-formated html; it removes all leading spaces and mangles empty lines.

This is a significant problem when posting nicely coloured code snippets like those produced by hilite.me or the SyntaxHilighter in WordPress.

A small hello world app ends up looking like this –

public class Hello1
public static void Main()
System.Console.WriteLine("Hello, World!");

Instead of this –

public class Hello1
   public static void Main()
      System.Console.WriteLine("Hello, World!");

Ahhh, much more readable. My way of solving this requires sed, so you’ll need a Linux installation, cygwin or Windows version of the command.

My hilite.me CSS looks like this –
border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;font-size:9px

Create a file called SedFixesForDotclear.sed.
Its content is

s/^$/<br/>/g #replace blank lines with <br/>
s/t/    /g #replace tabs with spaces - then the next line replaces the spaces
:l s/^((&nbsp)*) /1&nbsp/;tl #replace all leading spaces with &nbsp

Run the command –
sed -f SedFixesForDotclear.sed input.html > output.html

Paste the output file into your post.