无法使用moles来模拟MVC框架
我正在尝试为 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 论坛上看到了更多有关此问题的问题,但从未得到答案。 有人有解决办法吗?
I am trying to generate moles for the System.Web.Mvc DLL version 3, but I get the following error:
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.
I have seen more questions about this on the Microsoft forums, but never an answer.
Does anyone have a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这与已知问题相关。如果您决定将 Moles 与 MVC3 一起使用,您可以执行以下操作(我已经这样做了):
由于您所做的公钥切换,您在步骤 8 中生成的 System.Web.Mvc.Moles.dll 将引用真正的 MVC dll。您可以根据自己的喜好使用它来存根/摩尔 MVC 类。
This is related to a known issue. If you have your heart set on using Moles with MVC3, you can do the following (I have done this):
The System.Web.Mvc.Moles.dll you generated in step 8 will reference the real MVC dll, thanks to the public key switching you did. You can use it to stub/mole MVC classes to your heart's content.
您可以尝试排除有问题的类型:
You could try excluding problematic types:
要添加 @bhamlin 提到的内容,在步骤 #2 中,我还必须在 AssemblyInfo.cs 中进行以下更改以生成摩尔:
修改
为
,因为这是 System.ComponentModel.DataAnnotations.dll 中定义的内容
此程序集中的 CompareAttribute 基类(即 ValidationAttribute)。
To add to what @bhamlin mentioned, in step #2, I also had to make the following changes in AssemblyInfo.cs to generate moles:
Modify
to
as this is what's defined in System.ComponentModel.DataAnnotations.dll
Base class for CompareAttribute, which is ValidationAttribute, is in this assembly.