2011-02-11 126 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