Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to obtain public key for StrongNameKeyPair

I have ported developing to another computer and if i run project, i have this exception:

Unable to obtain public key for StrongNameKeyPair.

HibernateException: Creating a proxy instance failed

On original computer it works OK without problems.

I found on google that it is problem with some crypting and I should try "sn -m n", by I don't know how. sn.exe is in more folders, i tryed some run from command line but it writes:

Failed to open registry key -- Unable to format error message 00000005

I don't know if problem is because NHibernate or not, there are more similar whitch dialogs and it throw this exception only in one case.

there is part of code whitch throw exception:

public IList<DTO> GetAll(GridSortOptions sortOptions, DTOListModel<DTO> listModel)
{
    return GetAllCriteria(sortOptions, CreateCriteria(), listModel).List<DTO>();
}

No one project from solution use signing. I don't understand what exactly this errors means and what i should look for.

like image 805
Zdenek Avatar asked Apr 14 '11 07:04

Zdenek


3 Answers

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.

Your options are

  1. Get full control of C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys by modifying permissions which might not be recommended.

  2. Change your crypto key storage to user level by running the "sn.exe -m n" from the Windows SDK. http://msdn.microsoft.com/en-us/library/k5b5tt23(v=VS.90).aspx This will put crypto key stores under under your users local profile which you should always have full contorl to.

There are several articles online that describe a similar problem. For example, see http://support.targetprocess.com/Default.aspx?g=posts&t=305.

like image 75
Dude0001 Avatar answered Dec 15 '22 01:12

Dude0001


Had a similar issue today with a different use case (a .NET service running on a W2008R2 box) but exactly the same error.

Using procmon I traced it back to a failed write on a key in C:/ProgramData/Microsoft/Crypto/RSA/MachineKeys.

Following the guidance to add EVERYONE with special permissions on the folder as noted here fixed the problem: http://toastergremlin.com/?p=432

Also, make sure you add EVERYONE @ local machine and not EVERYONE @ your domain!

like image 45
NikG Avatar answered Dec 15 '22 02:12

NikG


For anyone else who comes across this, I just had the same exception, on a physical machine. Nothing changed overnight, but this exception started presenting in the morning.

Turned out to be low disk space issue, and the dynamic proxy assemblies couldn't be written to disk. Only realised this because I happened to notice the Windows 'low disk space' icon when it appeared briefly. :-P

Clearing out a bunch of (big) temp files made the problem go away.

like image 43
RJ Lohan Avatar answered Dec 15 '22 02:12

RJ Lohan