包含自定义属性的DLL保持锁定状

时间:2011-02-11 22:22:18

标签: c# .net security attributes custom-attributes

我正在尝试编写一个属性来将安全性应用于方法。看起来像这样的东西:

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

所以我在另一个集会上拥有我的属性:

 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) {  }   
 }

到目前为止它的确有效。 我运行我的主程序并完成它的工作。

现在我去修改具有该属性的程序集,然后构建它。没问题。

我回到我的主程序中尝试构建并在那里失败。它无法复制新构建的dll,因为旧的dll仍然被进程使用。

有没有人知道这里会发生什么?

3 个答案:

答案 0 :(得分:1)

如果您使用的是VS2010,则vhost.exe无法释放该实例。你可以暂时结束它的进程,直到MS出来修复。

答案 1 :(得分:0)

听起来你在尝试重建它之前还没有退出主程序。检查正在运行的进程以获取对主程序或安全属性dll的引用。 Process Explorer在这里可以提供真正的帮助。

答案 2 :(得分:0)

一直在解决同样的问题,它归结为我们使用testaccessors测试私有方法的事实。卸载unittest项目时,程序集将被释放。编译时我们的程序集被锁定。尚未找到解决方案,但已向ms提交了一个错误。你在使用testaccessors吗?

另见Assembly is being used by another processhttps://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