使用ReSharper(8.2.2)和VS 2013运行我的测试用例时出现了一个奇怪的错误.
演示问题的简化测试用例仅包含两行代码:
CallContext.LogicalSetData("mydata", new ActivityStack());
var evidence = AppDomain.CurrentDomain.Evidence;
Run Code Online (Sandbox Code Playgroud)
其中ActivityStack是可序列化的自定义类型.当测试用例通过ReSharper运行时,第二行会抛出异常:
System.Runtime.Serialization.SerializationException was unhandled by user code
HResult=-2146233076
Message=Type is not resolved for member 'CSG.Framework.Operations.ActivityStack,CSG.Framework, Version=15.2.0.0, Culture=neutral, PublicKeyToken=e7ab1d859f54b223'.
Source=mscorlib
StackTrace:
at System.AppDomain.get_Evidence()
at System.AppDomain.get_Evidence()
at CSG.Framework.Utilities.AppDomainLauncher`1..ctor(String appDomainName) in d:\Work\Git\Framework\Src\Library\Framework\Utilities\AppDomainLauncher.cs:line 40
at CSG.Framework.UnitTest.AppDomainLauncherTests.LaunchClassFromCallingAssembly() in d:\Work\Git\Framework\Src\Library\Framework.UnitTest\Utilities\AppDomainLauncherTests.cs:line 52
InnerException:
Run Code Online (Sandbox Code Playgroud)
即使当前AppDomain在BaseDirectory上看起来具有正确的路径,其中可以找到包含该类型的程序集,CLR似乎仍然使用ReSharper bin路径根据Fusion日志探测程序集.如果我将程序集复制到ReSharper bin文件夹,问题就会消失,但我不认为这是正确的解决方案.我试图在当前的AppDomain上订阅AssemblyResolve事件,但是没有调用处理程序.
融合日志:
*** Assembly Binder Log Entry (1/23/2015 @ 12:28:54 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll …Run Code Online (Sandbox Code Playgroud)