-
-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock.Of of Excel interop classes fails to initialize #1072
Comments
@killergege, Unfortunately I don't have a copy of the Excel v12 type library available. Could you possibly provide an assembly containing the above two tests, compiled against the old versions where everything passed? If you could ensure that the COM interfaces get embedded in the assembly, that would allow me to investigate what changes in the type libraries make Moq fail. |
We are using the nuget package to get the interop objects : https://www.nuget.org/packages/microsoft.office.interop.excel/ |
Ah, excellent! I wasn't aware of that NuGet package. Thank you for pointing me towards it... that should indeed be sufficient. |
@killergege, I've compared the Excel COM interop libraries. They appear to differ in (among other things) the presence or absence of Moq queries for this attribute in some places to recognize captured variables and anonymous types (those can show up in LINQ queries that use query comprehension syntax). In the current version, Moq erroneously enters into this "then" clause when it shouldn't... and that's what makes your code fail. Not yet sure how to fix this properly, but at least a fix is possible. A very crude fix would consist of adding an |
@killergege, since previous versions of Moq failed with different error messages, I can't completely rule out other causes for failure in a real-world use case. If problems with mocking |
I have a project that has a lot of tests on Excel interop classes.
Those were working fine with my current test project (net452, Moq 4.8, Microsoft.Office.Interop.Excel v12.0.4518.1014, NUnit v3.12...)
But after upgrading to Moq 4.14 & Microsoft.Office.Interop.Excel v15.0.4795.1000, all the Mock.Of on interop classes fail to initialize.
I had other setup issues following interop upgrade (because they stated to use
dynamic
in some places, instead ofobject
) but it seems that this is a different problem.The error is different based on the Moq version, but they all fail :
Moq v4.13.1
Moq v4.14.6
Is it expected?
Do you have a workaround ?
Replacing all the
Mock.Of<>()
bynew Mock<>() + setup
is a lot of work and adds a lot of "useless" rows...The text was updated successfully, but these errors were encountered: