加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.net – 不能使用moles来模拟MVC框架

发布时间:2020-12-16 03:25:16 所属栏目:asp.Net 来源:网络整理
导读:我试图为System.Web.Mvc DLL版本3生成痣,但是我收到以下错误: Moles : info : metadata : loading C:TFS.as12.ProjectsProject XMainSource3rdPartyComponentsMVC3System.Web.Mvc.dll Moles : info : compilation : output assembly name: System.We
我试图为System.Web.Mvc DLL版本3生成痣,但是我收到以下错误:

Moles : info : metadata : loading C:TFS.as12.ProjectsProject XMainSource3rdPartyComponentsMVC3System.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 MolesbinMicrosoft.Moles.targets(79,5): error MSB3073: The command ""C:Program Files (x86)Microsoft Molesbinmoles.exe" @"C:TFS.as12.ProjectsProject XMainSourceX.WebX.Web.Base.Mvc.UnitTestobjDebugMolesmoles.args"" exited with code -1002.

我在微软论坛上看到了更多关于此的问题,但从来没有回答过.
有没有人有办法解决吗?

解决方法

这与 known issue有关.如果您已经开始使用带有MVC3的Moles,您可以执行以下操作(我已经这样做了):

>下载MVC3 source code.
>从Properties / AssemblyInfo.cs中删除[SecurityTransparent]
>使用sn.exe从真实的MVC dll中提取MS公钥:“sn -e System.Web.Mvc.dll ms_public_key.snk”
>告诉VS在签署假MVC dll时使用该公钥(您可以在项目属性,签名下执行此操作).确保选中“仅延迟标志”框.
>构建.现在你有了一个用MS公钥签名的虚假MVC dll.但你不能将它用于任何事情,因为它不会通过签名验证.
>再次使用sn.exe为您的假dll注册跳过验证:“sn -Vr System.Web.Mvc.dll”< ---这需要是你的伪造的
> GAC你的伪造的gacutil.exe:“gacutil -if System.Web.Mvc.dll”< ---再次,假的
>运行痣.我强烈建议你存储整个dll,因为你不想再这样做了.
>删除skip-verification:“sn -Vu System.Web.Mvc.dll”< ---假的
>恢复真正的DLL:“gacutil -if System.Web.Mvc.dll”< ---真实的
>删除你的邪恶假MVC dll,以免有人意外地使用它.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读