Moq & Interop Types: works in VS2012, fails in VS2010?

后端 未结 4 721
攒了一身酷
攒了一身酷 2020-12-03 11:43

I have a .NET library project with about 500 unit tests. All these tests run fine in Visual Studio 2012. However, some of my tests fail in Visual Studio 2010. In these faili

4条回答
  •  攒了一身酷
    2020-12-03 12:25

    I tried to reproduce this, and for me it doesn't work even in VS 2012.

    When you compile a project using "Embed Interop Types", the C# compiler generates an internal type that has only the members you are accessing, and the implementation actually seems to use IDispatch to call the method of the COM object by id.

    From your description I understand that your test project in VS 2012 does not access the properties (not even in order to mock them), but the test still succeeds and the generated type in the test project does have these members.

    If this is indeed what you are experiencing, can you please look at the content of your test .dll and see how the interop type was generated? You can use a tool such as ildasm.exe.

    If the interop type in the test .dll contains all the members, even those you don't access in the test, this may give a clue that the difference is related to the way the interop types are generated in VS 2012.

    Also, if you can attach a small minimal VS 2012 solution which reproduces the problem, it may greatly help in diagnosing this.

提交回复
热议问题