Unable to obtain public key for StrongNameKeyPair

Yesterday I had to build our entire application on a box that is not my own. Sounds easy enough, just

  1. Grab all code from source control
  2. Grab any 3rd party libs
  3. Build

All went ok until I tried to build a project that used the Castle Windsor IOC container, and I got this  :

System.ArgumentException: Unable to obtain public key for StrongNameKeyPair..

System.Reflection.StrongNameKeyPair.nGetPublicKey(Boolean exported, Byte[] array, String container) System.Reflection.StrongNameKeyPair.get_PublicKey() System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes) System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) Castle.DynamicProxy.ModuleScope.CreateModule(Boolean signStrongName) Castle.DynamicProxy.ModuleScope.ObtainDynamicModuleWithStrongName() Castle.DynamicProxy.ModuleScope.ObtainDynamicModule(Boolean isStrongNamed) Castle.DynamicProxy.Generators.Emitters.ClassEmitter.CreateTypeBuilder(ModuleScope modulescope, String name, Type (blah blah snip)


Massive sadness…..   <|:-(

Turns out that this is due to a permissions issue on the box I was using, where I did not have the correct privileges to create a new strong name key, due to to folder access rights. Boo

There is a special directory which has all the Crypto stuff in it :


  • DSS
  • Keys
  • RSA
  • SystemKeys

And it turns out you need to have full access to the C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys folder in particular.

One I found that folder and gave myself full read/write/delete access, my problem was solved.

Hope that helps someone else out. There was something like this on Stack Overflow which also helped me out : http://stackoverflow.com/questions/2425667/strongnamekeypair-problem-when-attempting-to-use-moq



  1. Were you trying to do the “right thing” and do your dev as a normal user rather than logging on as admin?
    While WIN 7 and 8 give quite good prompting for privilege elevation for normal stuff, development still seems to have lots of holes which cause posts like this one. I wish microsoft would document it in some way or at least have meaningful error messages. ERRNO=5 is your friend!


    1. I was absolutely trying to do the right thing, I just couldn’t use my machine (as it was being rebuilt for a completely different reason), and then this Exception happened.

      Not that obvious really.

      Like I say I hope it helps someone else out


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s