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.