5

我正在尝试为 System.Web.Mvc DLL 版本 3 生成痣,但出现以下错误:

 Moles : info : metadata : loading C:\TFS.as12.Projects\Project X\Main\Source\3rdPartyComponents\MVC3\System.Web.Mvc.dll
    Moles : info : compilation : output assembly name: System.Web.Mvc.Moles
Moles : warning : metadata : failed to load module System.Web.Mvc.dll:
Moles : warning : metadata : Inheritance security rules violated by type: 'System.Web.Mvc.CompareAttribute'. Derived types must either match the security accessibility of the base type or be less accessible.
Moles : warning : metadata : Inheritance security rules violated by type: 'System.Web.Mvc.RemoteAttribute'. Derived types must either match the security accessibility of the base type or be less accessible.
Moles : error : code : assembly contains no types or failed to load properly
  00:00:00.53> moles generator 1 errors, 3 warnings

    Moles compilation FAILED - 6,18794176354816s
C:\Program Files (x86)\Microsoft Moles\bin\Microsoft.Moles.targets(79,5): error MSB3073: The command ""C:\Program Files (x86)\Microsoft Moles\bin\moles.exe" @"C:\TFS.as12.Projects\Project X\Main\Source\X.Web\X.Web.Base.Mvc.UnitTest\obj\Debug\Moles\moles.args"" exited with code -1002.

我在 Microsoft 论坛上看到了更多关于此的问题,但从未得到答案。有没有人有办法解决吗?

4

3 回答 3

3

这与一个已知问题有关。如果您决定将 Moles 与 MVC3 一起使用,您可以执行以下操作(我已经这样做了):

  1. 下载 MVC3源代码
  2. 从 Properties/AssemblyInfo.cs 中删除 [SecurityTransparent]
  3. 使用 sn.exe 从真正的 MVC dll 中提取 MS 公钥:“sn -e System.Web.Mvc.dll ms_public_key.snk”
  4. 告诉 VS 在签署您的假 MVC dll 时使用该公钥(您可以在项目属性下执行此操作,签名)。确保选中“仅延迟符号”框。
  5. 建造。现在你有了一个用 MS 公钥签名的假 MVC dll。但是你不能将它用于任何事情,因为它不会通过签名验证。
  6. 再次使用 sn.exe 为您的假 dll 注册跳过验证:“sn -Vr System.Web.Mvc.dll”<--- 这需要是您的
  7. 用 gacutil.exe GAC 你的假的: "gacutil -if System.Web.Mvc.dll" <--- 再次,假的
  8. 跑痣。我强烈建议您存根/摩尔整个 dll,因为您不想再次这样做。
  9. 去掉skip-verification: "sn -Vu System.Web.Mvc.dll" <--- 假的
  10. 还原真实的dll:“gacutil -if System.Web.Mvc.dll”<---真实
  11. 删除你邪恶的假 MVC dll,以免有人意外使用它。

您在第 8 步中生成的 System.Web.Mvc.Moles.dll 将引用真正的 MVC dll,这要归功于您所做的公钥切换。您可以使用它来存根/摩尔 MVC 类到您的心脏内容。

于 2011-10-28T18:31:08.567 回答
0

您可以尝试排除有问题的类型:

<Moles ...
   <StubGeneration ...
       <Types>
          <Remove TypeName="System.Web.Mvc.CompareAttribute" />
          <Remove TypeName="System.Web.Mvc.RemoteAttribute" />
       </Types>
   <MoleGeneration>
       <Types>
          <Remove TypeName="System.Web.Mvc.CompareAttribute" />
          <Remove TypeName="System.Web.Mvc.RemoteAttribute" />
       </Types>
   </MoleGeneration>
于 2011-08-23T12:33:01.107 回答
0

为了补充@bhamlin 提到的内容,在第 2 步中,我还必须在 AssemblyInfo.cs 中进行以下更改以生成痣:

调整

[assembly: AllowPartiallyTrustedCallers]

[assembly: AllowPartiallyTrustedCallers(PartialTrustVisibilityLevel = PartialTrustVisibilityLevel.NotVisibleByDefault)]

因为这是 System.ComponentModel.DataAnnotations.dll 中定义的

派生类型必须与基类型的安全可访问性匹配,或者难以访问

CompareAttribute的基类(即ValidationAttribute)位于此程序集中。

于 2013-10-29T16:33:09.043 回答