Reputation: 8337
I am having trouble with making Unity play nice with the new Fakes framework (formerly pex & moles)
When I tried to create fakes of the unity interception library, it caused my unit test to run fine when debugging, but breaks with an
InvalidProgramException - Common Language Runtime detected an invalid program.
The question is why? Why the different behavior in debug vs. release? The unit test pass, when debugging, but breaks with the above exception when I choose to run it, instead.
Upvotes: 0
Views: 734
Reputation: 172666
If you are faking Unity, you are doing it wrong! The fact that you need to fake Unity means you are abusing unity as a Service Locator (anti-pattern). Instead, you should not call Unity from within your application and only use it inside your Composition Root. This prevents you from having to fake Unity at all.
Always remember the intuition rule of programming: if it feels awkward, you are doing it wrong.
Upvotes: 1
Reputation: 16904
If I had to guess (never personally combined interception with fakes) I'd say you've got two frameworks that are both fiddling with stuff at an IL level, and that just can't end well.
Fakes works by (going from shady memory here) creating a duplicate "shim filled" variant of the assembly you're faking, and unity interception does IL weaving on the interception points - mix the two of those together and I'm not surprised that it's created an invalid sequence of IL.
Fixing it? Oof...don't use Fakes on any assembly you're performing interception on? Rely on more traditional mocking frameworks in those cases.
Upvotes: 0