Yesterday I had to build our entire application on a box that is not my own. Sounds easy enough, just
- Grab all code from source control
- Grab any 3rd party libs
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 :
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