12

I am running Visual Studio 2010 on a Windows 7 VM and trying to build a fairly large solution. When I try to do so, I get the error:

Cannot register assembly "C:\Development\ProjectName\Source\bin\Debug\AssemblyName.dll" - access denied.  Please make sure you're running the application as administrator.  Access is denied.  (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I have taken the following steps:

  1. Confirmed that I am in fact running Visual Studio 2010 as administrator.
  2. Restarted the VM.
  3. Confirmed that the assembly does exist exactly where Visual Studio is looking for it.
  4. Confirmed that administrator has full control over the relevant file.
  5. Cleaned and rebuilt the project (multiple times).

I have also found that building the project which creates AssemblyName.dll, manually registering it with RegAsm, and then building the project which requires AssemblyName.dll does not result in an error, but this is not a desirable workaround as it requires manual control. Can anyone give me some advice on how to solve this problem?

Many thanks.

CosmicComputer
  • 1,634
  • 1
  • 15
  • 15

4 Answers4

24

This particular issue happens when you are building an assembly project which has the 'Register for COM interop' checked under the Compile tab of the project properties. As Stephane said, you must right click -> Run as Administrator in order for it to register automatically.

If you already have the compiled assembly from a different machine, you can alternatively register it manually and reference the compiled assembly with the project to by-pass the issue.

StayOnTarget
  • 7,829
  • 8
  • 42
  • 59
J. Thompson
  • 461
  • 3
  • 9
  • 1
    But the OP specifically said they are running as admin, and still get the error. – StayOnTarget Sep 07 '18 at 17:48
  • This is the info I was REALLY trying to find. I just needed to understand WHY Visual Studio was trying to register the DLL during build! Thank you! – Joe Irby Apr 12 '19 at 17:34
3

When you ran VS2010, did you right-click and select "Run as administrator"? If not, it actually runs as a lower priviledged user. Once I selected "Run as administrator", this problem went away.

Stephane
  • 31
  • 2
2

I also ran into this error even though I was running VS 2015 as administrator.

In my case I found that manually cleaning up (ie deleting) bin\Debug\*.* for the project resolved the issue. Apparently some kind of file permissions or something was preventing the operation, and the error message may have been incorrect.

I'm not sure what was causing the file 'conflict' in the first place.

StayOnTarget
  • 7,829
  • 8
  • 42
  • 59
0

Similar to what UuDdLrLrSs said, when I tried to clear the bin folder, Windows gave an error on file access. Apparently another process was using the file - in my case, Microsoft Access.

After closing the associated program that had a file handle, the project built fine. (Although I'm still a little confused as to why it had a file handle on debug assemblies...)

Justin
  • 25
  • 1
  • 1
  • 6