A pleasant walk through computing

Comment for me? Send an email. I might even update the post!

Solving NancyFx Tokenizer keyChain.bin Invalid Read Type Request '115'

The Error

I was getting this error when running an ASP.NET solution using NancyFx:

System.Runtime.Serialization.SerializationException: 'Invalid read type request '115'.'

on this statement in my NancyBootstrapper:

container.Register<ITokenizer>(new Tokenizer());

There is only one mention of this error when searching Google, and it refers to using a sync service of some kind. So, not apparently related.

After quite a bit of sleuthing, I wondered about Nancy's keyChain.bin file, which I knew had been modified during a recent git rebase operation.

Sure enough, I checked out the file from a working branch and the bug went away. Interestingly, I had renamed and saved the "bad" file. When I renamed it back, the bug didn't recur. So, I don't really understand what went wrong, but it got fixed.

A simpler way to fix this would have been to rename or delete the keyChain.bin file, then let Nancy regenerate it.

Make it Better

I also was doing the wrong thing for the right reason. The (deprected) Nancy Token-Authentication requires a writable keyStore folder. By default, it gets created in the project root. I was marking the keyChain.bin file Build Type as Content and Copy Always, so it would be created in a first-deployment. But that meant storing the file in Git and it was always changing.

My current solution is to use a readme.txt placeholder file, and ignore keyChain.bin.

The better solution...I'll blog if successful...will be to write a custom FileSystemTokenKeyStore that stores the keyStore folder in App_Data, which is always writable.

My Ideal Markdown Editor - Thoughts and Reviews Part 1

Where I'm Headed

I've been meaning to blog about my ideal Mardown editor requirements, and which editors today get close to being my dream-editor-come-true.

I'll probably be editing this post, but it gives a good idea of what matters to me. In upcoming parts, I'll review some--not all--of the editors and announce a winner.

Spoiler!
My current Markdown editor is Markdown Monster, and I'm not expecting that to change. Still...we'll see!

Requirements

  1. Use a Git parser that at least supports GFM.
  2. Ideally, support MarkDig because it's fast and, itself, supports all MD flavors.
  3. Scripting/snippet support.
    1. Specifically, journal datetime, but I have other snippets I've become used to.
  4. Addin support.
    1. Want to be able to create/publish using my static site generator.
  5. Standard MD behaviors
  6. Standard Editor behaviors
    1. Including block editing
  7. Supported. Editors seem to come and go.
  8. Drag-and-drop image paths.

Extras I've Found I Like

  1. Preview window outside the editor.
  2. Automatic check-box bullets.
    1. And, auto-checking from the editor. See the Android app iA Writer.
  3. Open to end of document. Would love to do this per-document, so my journal opens to the end.
  4. YAML handling.
  5. Tabbed interface simultaneous with separate instances. I love being able to do my journal summary without changing settings.
  6. Using Ctrl-K (or whatever creates a link), automatically includes whatever's in the clipboard.'
  7. When pasting HTML, the ability to strip extras down to just the Markdown, instead of pasting the HTML styles, etc.
  8. When pasting a link, if it's just a link then automatically surround with <>.

Editors

Desktop

Android

References

My Why and How of posh-git: Context Menu, Transcripts, and TF.exe

I'd been pretty happy using Cmd to run my Git command line. I didn't have requirements that forced me to use something else. But I hadn't really compared the three main command-line shells for Git on Windows (Command, Powershell, Git-Bash), or thought about features I wanted or maybe didn't know I wanted.

I didn't do an extensive review, just an exploration to see whether I wanted to change my default. The answer turned out to be "yes"!

Contents

Skip to the End!

I was persuaded by all things git's Edward Thomson's argument that Windows users shouldn't use Git-Bash for the simple reason that we shouldn't have to use a foreign operating system's shell to work with Git.

I was also persuaded by Scott Hanselman and Phil Haack that using Powershell with posh-git was an awesome Windows solution. I was even more convinced by Dave Hein's article showing how to create a simple transcription method to record git sessions. That could be a lifesaver.

Here's my current setup.

Step 1 - Install Git for Windows

You can follow the defaults and be fine. Some people recommend not changing your local PATH environment variable, but I think it's OK and reduces some friction. I do have preferred configuration answers and may blog them in the future.

Step 2 - Install posh-git

These steps assume git.exe is on your path. Steps mostly copied from Dave Hein.

  1. Open Powershell. Check the execution policy with Get-ExecutionPolicy. It should be RemoteSigned or Unrestricted1.
  2. cd ~\Documents and create directory GitHub.
  3. cd GitHub
  4. git clone https://github.com/dahlbyk/posh-git.git.

Step 3 - Create a Powershell profile

Warning
Many sites that show examples of Powershell profiles for posh-git are for older versions, especially when it comes to changing the prompt.

  1. Open Documents and create a directory WindowsPowerShell if necessary.
  2. In WindowsPowerShell, use a text editor to create a file named posh-git.profile.ps1

This is my script.

    $Host.UI.RawUI.BackgroundColor = 'Black'
    $Host.UI.RawUI.ForegroundColor = 'Gray'
    Clear-Host
    
    $Env:Path = "$Env:ProgramFiles\Git\bin" + ";" + $Env:Path
    Push-Location (Resolve-Path "$Env:USERPROFILE\Documents\GitHub\posh-git")
    
    # Import the posh-git module, first via installed posh-git module.
    # If the module isn't installed, then attempt to load it from the cloned posh-git Git repo.
    $poshGitModule = Get-Module posh-git -ListAvailable | Sort-Object Version -Descending | Select-Object -First 1
    if ($poshGitModule) {
        $poshGitModule | Import-Module
    }
    elseif (Test-Path -LiteralPath ($modulePath = Join-Path (Get-Location) (Join-Path src 'posh-git.psd1'))) {
        Import-Module $modulePath
    }
    else {
        throw "Failed to import posh-git."
    }
    
    Pop-Location
    
    # Settings for the prompt are in GitPrompt.ps1, so add any desired settings changes here.
    # Example:
    #     $Global:GitPromptSettings.BranchBehindAndAheadDisplay = "Compact"
    
    $Global:GitPromptSettings.DefaultPromptBeforeSuffix.Text = "`r`n"
    $Global:GitPromptSettings.DefaultPromptPath.ForegroundColor = 'Orange'
    
    Start-SshAgent -Quiet
    
    # Start a transcript
    #
    if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts"))
    {
        if (!(Test-Path "$Env:USERPROFILE\Documents\WindowsPowerShell"))
        {
            $rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell" -ItemType directory
        }
        $rc = New-Item -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts" -ItemType directory
    }
    $curdate = $(get-date -Format "yyyyMMddhhmmss")
    Start-Transcript -Path "$Env:USERPROFILE\Documents\WindowsPowerShell\Transcripts\PowerShell_transcript.$curdate.txt"
    
    # Alias TFS command line
    Set-Alias tf "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe"

Step 4 - Add Context Menu Entry

I frequently want to open a Git console by right-clicking in the folder. Git for Windows adds that for Git-Bash (unless you say not to). Here's the registry file to add context menu entries for our new posh-git setup.

Note
You need to replace the user profile path below with your own.

Windows Registry Editor Version 5.00

# Right-click on Explorer folder's empty space in right pane
[HKEY_CLASSES_ROOT\Directory\Background\shell\011PowershellPoshGit]
@="Open with Powershell posh-git"
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\011PowershellPoshGit\command]
@="powershell.exe -NoExit -ExecutionPolicy RemoteSigned -File C:\\users\\charl\\Documents\\WindowsPowerShell\\posh-git.profile.ps1"

Step 5 - Add Custom posh-git entry to Visual Studio Open Command Line Extension

I like Mads Kristensen's Open Command Line extension to Alt-Space open a command window. If you don't use it, skip this part.

  1. Open Visual Studio > Tools > Options > Environment > Command Line
  2. In "Select preset", choose Custom.
  3. Change "Friendly name" to something like "My posh-git"
  4. Command = powershell.exe
  5. Command arguments = -NoExit -ExecutionPolicy RemoteSigned -File C:\users\charl\Documents\WindowsPowerShell\posh-git.profile.ps1
  6. Save and exit

Results

You can now right-click inside a folder and open posh-git from a menu item.

Which, in my case, gives this console. I can run both Git commands and TFS commands.

I'll get the same console if I have a solution open in Visual Studio and press ALT-Space.

To Do

  • Explore installing and using the TFS cmdlets, which might improve my weird workflow, (see below).

A Summary of How I Got Here

I originally was going to make this a review/comparison of the three command lines, but by the end of my research I realized there wasn't much point (to me) in that.

Git-Bash was off the table. The only reason I could see using it was for git aliases that rely on Unix commands, and even that seemed iffy. I'd rather rewrite such alises using native Windows commands.

My requirements were:

  1. Open the console by right-clicking an Explorer folder and choosing from the menu.
  2. Open the console by using Mads Kristensen's Open Command Line extension.
  3. Be able to run TFS commands (tf.exe)2.
  4. Copy/paste to/from the console easily, i.e. CTRL-C, CTRL-V.
  5. Open an explorer window into my current folder using explorer . (note the dot after the command, which means "open here".)
  6. Dynamically resize the console contents.
  7. Scroll back through commands.
  8. Powerful command line if needed.

References

posh-git

Creating Context Menu Entry

TFS from Powershell

Git-Bash and/or Bash on Windows (they're not the same)

Miscellaneous


  1. Run PowerShell as administrator and call Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm

  2. I have a kind of crazy work flow where I use Git locally, but check in code to TFS remotely.