Friday, November 16, 2012

HibernateException: Creating a proxy instance failed –> Unable to obtain public key for StrongNameKeyPair issue

I stumbled upon the following exception for a webapp of a particular site:

HibernateException: Creating a proxy instance failed –> Unable to obtain public key for StrongNameKeyPair.

Strange thing because this was only for one site, the other sites which have the same code didn’t have this issue.

This link gave me a good start:

http://stackoverflow.com/questions/5659740/unable-to-obtain-public-key-for-strongnamekeypair

NHibernate is dynamically creating .NET assemblies (dynaic proxies) and needs to sign them. By default the Windows OS configures the crypto key storage to be machine level and stores the keys in C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys. Most likely your user can create (for example) a text file in this folder, but not delete it because you do not have full control.

After reading this, what I did was I went to IIS Manager and checked the identity for the app pool which was running the webapp.

It was set to ApplicationPoolIdentity which creates a virtual account with the name of the new application pool and run the Application Pool's worker processes under this account:

http://forums.iis.net/t/1173831.aspx

Setting the identity to NetworkService made the app work fine like in other sites.

No comments: