Unable to start kestrel - An attempt was made to load a program with an incorrect format

Hopefully this saves someone some time in the future.

I was developing a throw away ASP.NET Core app on .NET Full framework in Visual Studio 2017. I noticed that the Platform target was set to x86 (the default), so I changed it to AnyCPU then redeployed.

I tried to run it from the console (I love how I can just run a webapp from the console now… so awesome), but got the following error:

crit: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to start Kestrel.
System.AggregateException: One or more errors occurred. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Turns out that even though I had changed the Platform target via the Project Properties, there was a setting within the csproj that indicated an x86 runtime.

To solve the issue, open up the csproj file for your project and change the x86 part of the value of the RuntimeIdentifier element to x64.

So instead of (for example):

<RuntimeIdentifier>win7-x86</RuntimeIdentifier>

You want:

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

Save that and rebuild or redeploy your project.

For more information about the above, I first found the error message described at:

https://docs.microsoft.com/en-us/aspnet/core/publishing/iis#platform-conflicts-with-rid.

Information about the RuntimeIdentifer property, see https://docs.microsoft.com/en-us/dotnet/articles/core/tools/csproj#runtimeidentifier. For information about the RFID values, see https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog.

Setting up TortoiseSVN to connect to svn+ssh

I was tasked to help a customer move their subversion server to the “cloud” (azure in this instance).

Due to various factors, we chose not to use a VPN but rather go with svn+ssh to connect to the remote subversion repository.

Anyway, this post is to describe how to configure TortoiseSVN to connect to the svn+ssh remote server.

Firstly, the software I used:

Assumptions

  • I’m assuming you are using a keypair to authenticate with the svn+ssh service.
  • I’m also assuming that you have created a keypair that Putty can use. Follow the instructions at https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter8.html#pubkey-puttygen. If your keypair was generated using openssh, then you’ll need to convert it to a format that Putty can use. Puttygen can be used to do that, although it doesn’t support the newer format from openssh.
  • Lastly, I’m assuming your keypair uses a passphrase. If not, you definitely should be.

Configure Putty

We need to configure a new Saved Session in Putty that we will refer to later in TortoiseSVN. This will tell TortoiseSVN the connection details and private key to use when connecting to the svn+ssh service.

  1. Launch Putty.exe. If you used the msi installer, it should be on your desktop. You’ll the standard Putty dialog show:

    B2B2ACB4-FCEE-484F-9912-111C7F6E2D3F

  2. We need to tell Putty where to find our Private Key on disk. So in the left-hand panel drill down to Connection->SSH->Auth and you’ll see this:

    E655FCE2-5CF9-426C-A56B-D9D82BCD7AD1

  3. Enter in the path to your Private Key:

    B9CDF088-2160-4BB4-A36D-D3346BA6525B

  4. Now we need to tell Putty our Host connection details. So (1) go to the Session option. (2) enter in your Host and Port connection details; (3) Enter in a and in the text box below “Saved Sessions” label, (2) enter in a descriptive label then (3) click “Save” button. You’ll see that label show up in the list box below the text box. This has saved the details you entered into a named config so we can refer to it in TortoiseSVN.

    8AF062C9-7C21-4AD1-8A21-A505A91D1D88

  5. Finally, we must save these details as a Saved Session. In the text box below “Saved Sessions”, (1) enter in a descriptive label. I strongly recommend not using any spaces. It makes a big difference later on.

    Now (2) click on the “Save” button to save the details as that label.

    FB10F1E3-94A9-4258-8F2F-7C1964A4D5E2

  6. You can close Putty now (click the Cancel button).

Configure TortoiseSVN

We need to quickly configure TortoiseSVN to know how to connect to an svn+ssh connection.

  1. Open up your TortoiseSVN settings dialogs (you can find it in your Programs menu or by right-clicking in Windows Explorer and selecting TortoiseSVN -> Settings).

  2. Navigate to Network in the left-hand panel. In the “SSH client:” text box enter in the path to the TortoisePlink.exe utility. If you installed TortoiseSVN with the defaults, the path should be C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe:

    EE131FB3-9124-4579-903C-D0EDA23FF7DB

  3. Click OK.

Test the Connection

We can now attempt to connect to the remote subversion repository.

Open up the TortoiseSVN Repository Explorer and type in the url to the remote Subversion repository. The svns+ssh url is as follows:

svn+ssh://(username)@(putty_session_name)/(repository_name)/

Where:

  • username : The name given to you by the Subversion administator.
  • putty_session_name : The name we used in the Save Sessions text box in Step 4 in section “Configure Putty”. E.g. “examplesvn”
  • repostitory_name : The name of the repository you’re connecting to.

So for example, if Bob wanted to connect to the research repository, the url would be:

svn+ssh://bob.smith@examplesvn/research/

Note: If this is the first time you are attempting to connect to the remote Subversion repository, you will prompted on whether you trust the server you are connecting to and want to cache the server’s key.

BEBFD399-935E-43D4-BEBC-BB5D59D6B027

You will then be prompted for your Private Key passphrase:

D8A5352D-8AD4-44B0-A2F7-91EE582B87B1

And then re-prompt several more times. After which if everything was correct you’ll see your repository in the Repository Browser.

The reason why were you prompted several times for your passphrase is due to how svn protocol works whereby it makes multiple seperate connections to the server. And each connection requires a re-authentication. This will get very annoying after a short time.

To reduce the pain, we’ll use a utility called Pageant that will cache your decoded Private Key in memory after the first time you enter in your passphrase.

Setting up Pageant

The way Pageant works is that the first time it runs, it prompts you for your Private Key passphrase and then whenever Putty needs to use that Private Key, it uses the already decoded Private Key information to do the ssh handshake.

The easiest way of doing this, is running Pageant on Windows startup.

  1. Open up the Task Scheduler (otherwise known as Scheduled Tasks).

  2. Create a Basic Task by clicking on the “Create Basic Task…” in the Actions panel:

  3. Enter in a name for the task then click “Next >”.

  4. Select “When I log on” option for when you want the task to start. Then click “Next >”.

  5. Select “Start a program” for the action. Then click “Next >”.

  6. For the “Program/script:” value, enter in c:\Program Files (x86)\PuTTY\pageant.exe assuming you used the MSI installer for Putty. You also need to add the path to your private key into the “Add arguments” text box. Make sure you surround the path in double-quotes (just in case the path has spaces). So something like this:

    E4E33C88-DD94-49A9-B187-F8A72301658B

  7. Click Next >.

  8. If you’re happy with what you entered in, Click “Finish”.

Now you definitely want to test this out, so log out of Windows then log back in. When you log in, you should see the following prompt from Pageant:

2160FF9C-3E95-4693-8F3F-5BE9D7B12133

If the passphrase is correct, the dialog will just disappear.

From now on, when you connect to the remote Subversion repository, you will no longer be prompted for any passphase.

Happy days!

REPL Development using F# Interactive in Visual Studio Code

Now that we have Ionide installed, we can do REPL development by using the F# Interactive console (FSI).

There are a couple of ways of getting FSI to run your code:

  1. Sending the selected code to FSI.
  2. Sending the current line to FSI.
  3. Sending the whole file to FSI.

For the first two options, you don’t need to be working in an existing F# file. You can just create a new tab, start typing, select the code and send to FSI.

Caveat: I found that if you wanted Intellisense to work you needed to be working in a saved .fsx or .fs file (see reported issue). You can’t just change the language mode to F#.

Start FSI

To get started with FSI, you need to start it. To do so, open the Command Palette (P) and typing in “FSI: Start”.

The output panel will display like so:

Run code in FSI

Type in some F#. Then select the F# code you want to run and then select “FSI: Send Selection” from the Command Palette or type in Enter. This will take the code you have selected and run it in FSI and give you the result in the Output panel.

If you made a mistake in your F# code, you’ll see the compiler or runtime output in the Output panel. E.g.:

You can also send the whole file to FSI, however for that you need to be working in an existing file. Once you are working in an F# file, you can send the whole file (including your current unsaved changes) by selecting “FSI: Send File” from the Command Palette. However I found it easier to just select the content of the file (A) and then send the selection to FSI.

Setup SSH Keypair in Bitvise SSH Client

In case you use the bitvise SSH Client to connect to various ssh based services, here is how to set up a new SSH keypair.

Assumptions

  1. You are using Bitvise SSH Client 7.15. If you are using something different, the instructions may differ. See Bitvise for help then.
  2. You do not have an existing SSH keypair that you want to use.
  3. You know what public and private keys are (SSH keypair). See Understanding SSH Key Pairs

How to Create SSH Keypair

  1. Start Bitvise SSH Client.
  2. Under the Login tab, click on the Client Key Manager link:

  3. In the Client Key Manager dialog, select “Generate New” button:

  4. You should be able to keep the defaults, however definitely enter in a strong, unique passphrase. When done, press “Generate” button:

How to Export Public Key

Now that the SSH keypair is generated, we need to export the public key to give to the third-party/external service.

Note: I indicate to export as OpenSSH format this is the format that is used when configuring a linux remote machine for SSH/SFTP access and what github uses as well. Another online service might need it in SSH2 format so check.

  1. Again, in the Client Key Manager, highlight the ssh keypair you just generated, and select “Export” button.
  2. In the “Export Public or Private Key” dialog, select “Export public key” radio button then “OpenSSH format”. Then click “Export” button. Note that you’ll be prompted for a file location to save to.
  3. Find the file just created and depending on how the third-party requires it, either send the file or enter in the contents into the web-form, authorized_keys file, etc.

Finally I would also recommend exporting your Private key and keep it in a safe place in case you decide to use a different client or move computers, etc.

Getting started with F# in Visual Studio Code on OSX

Previously I showed how to install F# on OSX. In this post I’ll start showing you how you can start devloping F# in Visual Studio Code on OSX (macOS… whatever).

Assumptions

  • You are using OSX. These instructions may work on Windows, but I haven’t tested on Windows. Let me know if they do.
  • You have mono already installed. If not, follow the instructions.
  • You have Visual Studio Code (VSCode from now on) installed. If not, download it and install it.

Before we Get Started

These instructions were taken when using mono 4.4.2, VSCode 1.4, OSX 10.11.6, and Ionide extension v2.2.7. If any of the below does not work for you it may be due to differences in the versions of any of the above.

Installing Ionide Extension

The bulk of the F# support comes from the excellent Ionide project which I believe was originally developed for the Atom editor. There are a set of extensions for VS Code.

So as with all other extensions in VSCode, open up the Extensions view via one of these methods:

  • click on Extensions icon in View Bar, or
  • press X, or
  • Open up the Command Palette (P) and type in Install Extensions and press enter.

Now search for Ionide. You should see at least the three extensions below:

Install each extension (click on the green install button) then restart VSCode (rather than having to enable each extension). I installed them in the following order, though I’m assuming the order doesn’t matter: ionide-fsharp, ionide-fake, ionide-paket.

Now that Ionide is installed, you have should everything needed to get into F# now. There are a couple of ways you can do that:

I’ll describe each in the next set of posts.