Fakes sample on MSDN for WCF isolation doesn't work. [ShimNotSupportedException] and [InvalidProgramException] were seen.
I am trying to use Fakes to isolate one of our component from the external WCF dependencies.
So I found a demo code for WCF unit test with VS2012 Fakes at here: http://code.msdn.microsoft.com/windowsdesktop/Unit-Test-a-having-404c2a18
Unfortunately, the sample failed to work on one of my box. Though it succeeded on another box.
Here's the configurations for the 2 boxes, and I use VS2012 to run the sample on both boxes.
Win2008R2 + VS2012 + VS2010: Success
Win8 + VS2012 + VS2010: Failure
On the failed box I tried these approaches:
1. If I choose to run the case in VS2012, it gave me this error in the Output window:
------ Run test started ------
Exception has been thrown by the target of an invocation.
========== Run test finished: 0 run (0:00:03.7908642) ==========
2. If I choose to debug the case, it gave me the following error even before entering my test method. So no breakpoint in my test method was hit.
3. Finally, I have to try to run it with mstest from command line, and I got a trx file with the following stack trace:
Anybody can shed some light on my frustrated mind? I was expecting Fakes to be a powerful tool, never thought it could be this tricky.
- Edited by SoBigSoBig Wednesday, November 14, 2012 3:05 PM
I just checked a blog here: http://blog.degree.no/2012/09/visual-studio-2012-fakes-shimnotsupportedexception-when-debugging-tests/
It doesn't work.
It seems the ShimNotSupportedException is very legendary!
- Edited by SoBigSoBig Wednesday, November 14, 2012 4:13 PM
I had uploaded the MSDN sample. I replicated this issue in same environment i.e. Win 8, VS 2010 & VS 2012. In order to drill down I created a new Unit Test project(new solution) and added reference to System.ServiceModel dll. I added Fakes assembly for System.ServiceModel reference. I ran the default unit test(empty test method) and it failed with same error message. I removed the System.ServiceModel.Fakes and instead added Fakes assembly for System. This time it worked.
My initial thoughts are "Adding Fakes assembly for System.ServiceModel on Win 8 + VS 2010 + VS 2012 causes this error." I'll share if I find a workaround. Thanks.
- Edited by Atul.Verma Wednesday, November 21, 2012 6:04 PM
I have found a fix for this issue. The workaround is
Go to Test> Test Settings>Default Processor Architecture> and change to X64.
In my case it was X86. I changed it to X64, rebuild and ran the test ... it worked :)
- Proposed as answer by Fernando DeSantos Friday, November 30, 2012 4:43 PM