VS 2010 SP1 上的 Moles 0.94.51023.0 错误
我正在尝试使用 Moles 0.94.51023.0 来摩尔 VS 2010 SP1 中的 System.ServiceModel v4,但我不断收到以下错误: 命名空间“ssm::System.ServiceModel.Channels”中不存在类型或命名空间名称“IHttpCookieContainerManager”(您是否缺少程序集引用?)[my-test-project.Test\obj\Debug\Moles \ssm\mgcsproj] my-test-project.Test\mgcs 293022 43
此接口似乎已从 .NET 中的 System.ServiceModel.dll 中删除4.0,因为当我在对象浏览器中搜索时,我只能在 System.ServiceModel.dll v2.0.5.0 (Silverlight) 中找到它。
我可以使用moles.exe通过cmdline重现这一点,并且我尝试更改moles文件以仅生成我指定的类型名称,但它似乎没有任何区别。在我升级到 VS2010 SP1 之前,这工作正常,所以我怀疑这是一个错误,但任何帮助将不胜感激。
谢谢 缺口
I'm trying to mole System.ServiceModel v4 in VS 2010 SP1 with Moles 0.94.51023.0 and I keep getting the following errror:
The type or namespace name 'IHttpCookieContainerManager' does not exist in the namespace 'ssm::System.ServiceModel.Channels' (are you missing an assembly reference?) [my-test-project.Test\obj\Debug\Moles\ssm\m.g.csproj] my-test-project.Test\m.g.cs 293022 43
This interface appears to have been removed from System.ServiceModel.dll in .NET 4.0 as I can only find it in System.ServiceModel.dll v2.0.5.0 (Silverlight) when I search in the Object Browser.
I'm able to reproduce this via the cmdline using moles.exe and I've tried altering the moles file to only generate type names I specify but it doesn't appear to make any difference. This was working fine prior to my upgrade to VS2010 SP1 so I suspect it's a bug, but any help would be appreciated.
Thanks
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我自己也对此进行了调试,发现根本原因似乎是 VS2010 SP1 (以及相关的 GDR .NET 4 的知识库更新)更新一组 DLL,但不更新另一组:
%ProgramFiles(x86)%\Referenced Assemblies\ 中的 System.ServiceModel.dll与 .NET v4 安装中的 %windir%\Microsoft.NET\Framework64\v4.0.30319 不匹配...
VS 2010 SP1 更新后:
%Program Files(x86)%\Reference Assemblies\Microsoft\Framework。 NETFramework\v4.0\System.ServiceModel.dll ->文件版本 4.0.30319.1
%windir%\Microsoft.NET\Framework64\v4.0.30319\System.ServiceModel.dll ->文件版本 4.0.30319.225
在 VS 和 Reflector 的对象浏览器中比较这两个 dll,结果是 IHttpCookieContainerManager 接口已在较新的文件中删除。因此,我怀疑这是 .NET 探测发现较新的 DLL 和 Moles 在进行 Mole/存根生成时反映较旧的 DLL 的组合。我能够通过手动运行 Moles exe 来为较新的 DLL 手动生成 Moles dll,无需任何类型的引用路径,这与在构建期间添加一堆引用路径的 MSBuild 目标不同。
I debugged this on my own as well and found that the root cause appears to be that VS2010 SP1 (and the related GDR KB update for .NET 4) update one set of DLLs but not another:
The System.ServiceModel.dll in %ProgramFiles(x86)%\Referenced Assemblies\ doesn’t match the one in the .NET v4 install at %windir%\Microsoft.NET\Framework64\v4.0.30319...
Post VS 2010 SP1 update:
%Program Files(x86)%\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.ServiceModel.dll -> File version 4.0.30319.1
%windir%\Microsoft.NET\Framework64\v4.0.30319\System.ServiceModel.dll -> File version 4.0.30319.225
Comparing these two dlls in the Object Browser in VS as well as in Reflector yields the result that the IHttpCookieContainerManager interface has been removed in the newer file. So I suspect that this is a combination of .NET probing finding the newer DLL and Moles reflecting over the older one when doing mole/stub generation. I was able to manually generate a Moles dll for the newer DLL by running the Moles exe manually with no reference paths of any kind as opposed to the MSBuild target that adds a bunch of ref paths during a build.
我不知道为什么会发生这种情况,但我遇到了同样的问题,我通过使用 Moles 类型过滤器解决了它,并且只包含我真正需要的过滤器(这有一个很好的副作用编译速度大大加快!!)。这是我正在使用的
.moles
文件示例:I don't know why that happens, but I had the same issue, and I resolved it by using Moles type filters, and only including the ones I really need (which has the nice side-effect of speeding up compilation quite a lot!!). This is an example
.moles
file I'm using:看起来 Moles 用来编译的 System 和 System.ServiceModel 程序集之间存在冲突。
我最近安装了 Microsoft .NET Framework 4.5。
卸载并重新安装 4.0 后一切正常。
It looks like it was a conflict between the System and System.ServiceModel assemblies that Moles was using for compilation.
I had recently installed the Microsoft .NET Framework 4.5.
After uninstalling this and re-installing 4.0 everything worked.
好吧,万一有人正在使用遗留代码并且碰巧被迫使用 Microsoft Moles,我已经对这个主题进行了广泛的挖掘,并希望能够使一些人免于我遇到的愤怒和沮丧。
我尝试使用已接受的答案的建议,这意味着转到 Moles 目录(在 C:\Program Files.. 中)并以管理员身份运行命令行实用程序 (moles.exe)。有很多选项,其中之一允许您包含引用的程序集(如上所述)。
但是,即使尝试在没有引用程序集的情况下运行该实用程序,该实用程序最终也会使用预定义的引用程序集路径调用 C# 编译器 (csc.exe),这就是我得出的结论,.NET Framework 版本之间会发生混淆。我无法让它包含这些程序集路径。
我的具体情况是,我试图摩尔一个自定义程序集,但是,显然,因为我在这台机器上安装了.NET 4.5,所以它在编译时抱怨 System.Collections.Generics IReadOnlyCollection、IReadOnlyDictionary 和我认为的另一个。
解决方案:我使用的唯一解决方案是使用 Mole 过滤器,我在其他帖子和 Microsoft Moles 网站上读到过该过滤器(有一个 . NET 4.5 故障排除主页)。在 Visual Studio 中,我只需通过在解决方案资源管理器中右键单击,将 Moles 程序集添加到我引用的自定义程序集的单元测试项目中。然后我尝试构建。对于我收到的每个错误,我都会注意到有问题的类,并通过将以下内容添加到 moles 文件中来排除它们被 Shimmed 或 Stubbed:
现在显然,如果您需要您想要的类,那么这将不起作用。从摩尔/存根生成中排除,但是对于我的情况来说,它工作得很好,因为有问题的类并不重要,而且我不需要在这些类中存根或填充任何内容。
Well, in case anyone is working with legacy code and happens to be cornered into using Microsoft Moles, I've done extensive digging on this topic and hope to save some from the anger and frustration I encountered.
I tried using the accepted answer's suggestion, which meant going to the Moles directory (in C:\Program Files..) and running the command line utility (moles.exe) as Administrator. There a lot of options, one of which allows you to include referenced assemblies (as suggested above).
However, even when trying to run the utility without referenced assemblies, the utility ultimately calls the C# compiler (csc.exe) with pre-defined referenced assembly paths, which is where I conclude that the confusion between .NET Framework versions occurs. I couldn't get it not to include these assembly paths.
My specific scenario was that I was trying to Mole a custom assembly, however because, apparently, I had .NET 4.5 installed on this machine, it was complaining upon compilation about System.Collections.Generics IReadOnlyCollection, IReadOnlyDictionary, and I think one other.
Solution: The only solution I got to work was to use Mole filters, which I read about on other posts and on the Microsoft Moles website (there is a special link for .NET 4.5 troubleshooting on the main page). In Visual Studio, I simply added the Moles assembly to my unit test project for my referenced custom assembly via right click in Solution Explorer. I then tried to build. For each error I received, I noted the offending classes and excluded them from being Shimmed or Stubbed by adding the following to the moles file:
Now clearly that's not going to work if you need the classes that you're excluding from mole/stub generation, however for my case it worked fine because the offending classes were not important and I wouldn't be needing to Stub or Shim anything in those classes.