2011-02-11 68 views
0

我正在尝试编写属性以将安全性应用于方法。东西会看起来像这样:包含自定义属性的DLL保持锁定状态

[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仍然被一个进程使用。

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

+0

你有2把Visual Studio中的窗户打开? – NotMe 2011-02-11 22:29:49

+0

不是。但如果我关闭并重新打开它的作品。 – Burcephal 2011-02-11 22:31:09

+0

但如果我再次返回并修改程序集,则会失败。 – Burcephal 2011-02-11 22:31:31

回答

1

如果您使用的是VS2010,则vhost.exe不会释放实例存在问题。您现在可以结束进程,直到MS出现修复程序。

0

这听起来像你还没有退出你的主程序,然后再尝试重建它。检查您的正在运行的进程,以查看您的主程序或安全属性DLL。 Process Explorer在这里可以是一个真正的大帮助。

0

刚刚解决同样的问题,它归结为我们使用testaccessors来测试私有方法的事实。当卸载unittest项目时,程序集被释放。编译时我们的程序集会被锁定。还没有找到解决方案,但已经向ms提交了一个bug。你在使用测试存储器吗?

另见Assembly is being used by another processhttps://stackoverflow.com/questions/6895038/testaccessor-impl-of-codeaccesssecurityattribute-locks-assembly

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