【问题标题】:DLL containing custom attribute remains locked包含自定义属性的 DLL 保持锁定状态
【发布时间】:2011-08-01 16:07:18
【问题描述】:

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

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

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

【问题讨论】:

  • 您是否打开了 2 个 Visual Studio 窗口?
  • 不。但是如果我关闭它并重新打开它就可以了。
  • 但是如果我返回并再次修改程序集,它会失败。

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 感谢您的回答。所以我也试过了,没有机会。进程资源管理器告诉它来自devenv.exe,我们已经知道了。
    【解决方案3】:

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

    另见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

    【讨论】:

    • 我没有使用 testaccessors,但很欣赏这些信息。我将调查哪个其他库可能导致相同的问题。 Spring.NET 可能是?
    猜你喜欢
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 2013-01-24
    • 1970-01-01
    • 2013-11-26
    • 2020-08-13
    相关资源
    最近更新 更多