0

I am trying to write an attribute to apply security to a method. Something that would look like this:

[CustomAuthorization(SecurityAction.Demand)]
public void DoSomething()
{
  //Do Something
}

so I have my Attribute on another assembly:

 public sealed class AuthorizationAttribute : CodeAccessSecurityAttribute
 {      
        public override IPermission CreatePermission()
        {
                if (!/*authorize here*/)
                {
                     return new CustomPermission(PermissionState.Unrestricted);
                }
                throw new Exception("IdentificationFailure.");
            } 
        }

        public AuthorizationAttribute(SecurityAction securityAction)
            : base(securityAction) {  }   
 }

So far it works. I run my main program and it does its job.

Now I go and to modify the assembly having the attribute, build it. no problem.

I go back in my main program try to build and there it fails. It cannot copy the new built dll because the old one is still in use by a process.

Does anybody have any idea what would be happening here?

Burcephal
  • 445
  • 4
  • 9

3 Answers3

1

If you're using VS2010, there is an issue with vhost.exe not releasing the instance. You can end process on it for now until MS comes out with a fix.

Dustin Davis
  • 14,482
  • 13
  • 63
  • 119
0

It sounds like you haven't exited your main program before trying to rebuild it. Check your running processes for references to your main program or your security attribute dll. Process Explorer can be a real big help here.

villecoder
  • 13,323
  • 2
  • 33
  • 52
  • Thanks for the answer. So I tried that too, and no chance.The process explorer tells it comes from the devenv.exe, which we already knwew. – Burcephal Feb 11 '11 at 22:33
0

Just been trouble shooting the same issue and it boiled down to the fact that we were using testaccessors to test private methods. When unloading the unittest projects, the assembly is released. Our assembly gets locked when compiling. Haven't found a solution to this yet, but have submitted a bug to ms. Are you using testaccessors?

Also see Assembly is being used by another process and https://stackoverflow.com/questions/6895038/testaccessor-impl-of-codeaccesssecurityattribute-locks-assembly

MS bug: https://connect.microsoft.com/VisualStudio/feedback/details/682485/use-of-testaccessor-and-impl-of-codeaccesssecurityattribute-locks-assembly#details

Community
  • 1
  • 1
jaspernygaard
  • 3,098
  • 5
  • 35
  • 52
  • I am not using testaccessors but appreciate the information. I will investigate though which other library could be causing the same issue. Spring.NET may be? – Burcephal Aug 01 '11 at 23:57