CSLAs WCF usage when running XUnit tests in vs test explorer causes an Impersonation Exception
<p>We're using XUnit 2.1.0 from NuGet with the relating runners, console and visualstudio as documented <a href="http://xunit.github.io/docs/getting-started-desktop.html%20here" rel="nofollow">here</a> under the "running tests with visual studio" heading and relating content.</p>

<p>I'm also using Visual Studio 2015 Enterprise Update 2.
The only thing that's reasonably out of date is CSLA, we're on 4.0.1 (I think 5 years old?)</p>

<p>When we run any tests that require a DataPortal fetch, the test falls over as soon as the DataPortal fetch attempts to be sent to the server. WCF throws a "System.ServiceModel.FaultException" stating "Invalid token for impersonation - it cannot be duplicated." It's important to note none of the tests attempt to impersonate another user. the falling over happens in any test which attempts to use CSLA to do a DataPortal call.
We've recently moved over from xunit 1.x to 2.x through nuget, we used to run xunit from the xunit runner when testing our tests locally but that is now deprecated. The tests all ran absolutely fine through both the Gui and console runner for xunit 1.x. Now we have to use the visual studio runner with xunit 2.x we are getting this crazy exception.</p>

<p>edit: if you run xunit 2.x console runner from outside of visual studio the tests are also fine on 2.x, it's the visual studio side of things that is not working.</p>

<p>Stack trace below:</p>

<pre><code>Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc&amp; rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
   at Csla.Server.Hosts.IWcfPortal.Fetch(FetchRequest request)
   at Csla.DataPortalClient.WcfProxy.Fetch(Type objectType, Object criteria, DataPortalContext context) in D:\Dev\Insight\Trunk\Source\Lib\CSLA .NET\4.0\Source\Csla\DataPortalClient\WcfProxy.cs:line 162
   at Csla.DataPortal.Fetch(Type objectType, Object criteria) in D:\Dev\Insight\Trunk\Source\Lib\CSLA .NET\4.0\Source\Csla\DataPortal.cs:line 245
   at Csla.DataPortal.Fetch[T](Object criteria) in D:\Dev\Insight\Trunk\Source\Lib\CSLA .NET\4.0\Source\Csla\DataPortal.cs:line 170
</code></pre>

<p>Again this works fine if we run the tests from another test runner, either the old xunit test runner or CruiseControl.Net for example (We use CC.Net for continuous integration and this runs the tests fine)</p>