Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signing assembly Access Is Denied

I've recently upgraded to WIndows 7. When I try to sign the assembly in VS2010 I get an "Access is denied" error. I am logged as admin so I'm puzzled. What service account does VS uses that I should elevate its privilages?

Thanks,

Risho

like image 541
Risho Avatar asked Jan 05 '11 16:01

Risho


2 Answers

I don't know if it's Window 7 or the company policy, but I had to take ownership of the C:\Users\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys folder and give myself full control. This corrected the issue.

like image 123
Risho Avatar answered Sep 22 '22 08:09

Risho


Solution:

Run the following command from Administrator command prompt:

For 64-bit systems:

reg add HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\StrongName /v MachineKeyset /t REG_DWORD /d 0 

For 32-bit systems:

reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\StrongName /v MachineKeyset /t REG_DWORD /d 0 

The change affects immediately.

Why this happens:

MS Assembly Linker ALINK (AL.EXE) used by Visual Studio to sign assemblies creates a temporary crypto key during its work. Actually it uses some internal CLR functions for this, and the problem is that CRYPT_MACHINE_KEYSET flag is used by default. This requires elevation, and that's why running VS "as Administrator" works.

But, fortunately, I found that CLR has a global flag for StrongName signing, and it's stored in the system registry under

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\StrongName

and is controlled by DWORD value

MachineKeyset.

0 - use current user key set

1 - use machine key set (this is default)

Visual Studio is a 32-bit app and uses 32-bit version of AL.EXE for build. So on 64-bit systems it's subject to registry redirection, and the flag is located under the key

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\StrongName

It works on my VS2019, Win10, and .Net framework 4.8, but I didn't test it on previous versions though.

like image 34
mistika Avatar answered Sep 23 '22 08:09

mistika