c# - InvalidProgramException with shims in Visual Studio 2015 -
an similar question has been asked while ago not answered yet. , since setup little different, start new try:
i demonstrate shortened version of code, short version produces error.
i have method returns instance of system.printing.localprintserver
:
public class printserverprovider { public localprintserver provide() { return new localprintserver(new string[0], printsystemdesiredaccess.enumerateserver); } }
for method implemented unit test using shims:
[testclass] public class printserverprovidertests { [testmethod] public void provide_success() { using (shimscontext.create()) { bool constructorcalled = false; shimlocalprintserver.constructorstringarrayprintsystemdesiredaccess = (instance, props, access) => { constructorcalled = true; }; printserverprovider provider = new printserverprovider(); localprintserver server = provider.provide(); assert.isnotnull(server); assert.istrue(constructorcalled); } } }
in visual studio 2013 test works fine.
in visual studio 2015 (update 1), when tested method calls new localprintserver(...)
an
invalidprogramexception @ system.printing.localprintserver..ctor(string[] propertiesfilter, printsystemdesiredaccess desiredaccess) @ demoproject.printserverprovider.provide() in c:\projects\demoproject\program.cs:line 10. ...
is raised. (the normal productive call works fine. exception raised when running test method)
the referenced assemblies are:
- system.printing (v4.0.30319) c:\program files (x86)\reference assemblies\microsoft\framework.netframework\v4.5\system.printing.dll
- system.printing.4.0.0.0.fakes
- microsoft.qualitytools.testing.fakes (v2.0.50727) c:\program files (x86)\microsoft visual studio 14.0\common7\ide\publicassemblies\microsoft.qualitytools.testing.fakes.dll
system.printing.fakes
<fakes xmlns="http://schemas.microsoft.com/fakes/2011/"> <assembly name="system.printing" version="4.0.0.0"/> <stubgeneration> <clear/> </stubgeneration> <shimgeneration> <clear/> <add fullname="system.printing.localprintserver!"/> </shimgeneration> </fakes>
both projects (productive , test) use .net framework 4.5.
i tried resetting framework references. tried different versions of referenced assemblies. , tried 64bit , 32bit in variations.
in real code, use shims of other classes too. localprintserver
class exception occurs.
can explain causes invalidprogramexception
, how solve it?
i set bounty on this question, solved same answer. feel free post there if think answer bounty-worth.
Comments
Post a Comment