我尝试为System.Web.Mvc DLL版本3生成moles,但得到以下错误:
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.我在微软论坛上看到了更多关于这方面的问题,但从来没有得到答案。有谁有解决方案吗?
发布于 2011-10-29 02:31:09
这与known issue相关。如果你一心想在MVC3中使用Moles,你可以做以下事情(我已经做过了):
使用source code.
您在步骤8中生成的System.Web.Mvc.Moles.dll将引用真正的MVC dll,这要归功于您所做的公钥切换。您可以根据自己的需要使用它来存根/移动MVC类。
发布于 2011-08-23 20:33:01
您可以尝试排除有问题的类型:
<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>发布于 2013-10-30 00:33:09
为了补充@bhamlin提到的内容,在第2步中,我还必须在AssemblyInfo.cs中进行以下更改以生成moles:
修改
[assembly: AllowPartiallyTrustedCallers]至
[assembly: AllowPartiallyTrustedCallers(PartialTrustVisibilityLevel = PartialTrustVisibilityLevel.NotVisibleByDefault)]因为这是在System.ComponentModel.DataAnnotations.dll中定义的
派生类型必须与基类型的安全可访问性匹配,或者是较少可访问的
ValidationAttribute是CompareAttribute的基类,它位于此程序集中。
https://stackoverflow.com/questions/6620487
复制相似问题