机器规格 - 因为执行后的SerializationException?

时间:2014-11-06 14:08:16

标签: visual-studio-2012 .net-4.0 moq mspec

我在使用Machine.Specifications编写单元测试时遇到问题,同时使用Moq。当通过Resharper 8或运行mspec控制台运行测试时,我从R#获得一个弹出对话框,出现以下错误:

[Window Title]
Unit Test Runner

[Main Instruction]
Unit Test Runner failed to run tests


[Content]
System.Runtime.Serialization.SerializationException: Unable to find assembly 'ASSEMBLY.UNDERTEST, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

[Expanded Information]

Server stack trace: 
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm)
   at System.Runtime.Remoting.Messaging.SmuggledMethodCallMessage.FixupForNewAppDomain()
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Machine.Specifications.Runner.ISpecificationRunListener.OnFatalError(ExceptionResult exception)
   at Machine.Specifications.Runner.AggregateRunListener.<>c__DisplayClass17.<OnFatalError>b__16(ISpecificationRunListener listener)
   at Machine.Specifications.Utility.RandomExtensionMethods.Each[T](IEnumerable`1 enumerable, Action`1 action)
   at Machine.Specifications.Runner.AggregateRunListener.OnFatalError(ExceptionResult exception)
   at Machine.Specifications.Runner.Impl.AssemblyRunner.Run(Assembly assembly, IEnumerable`1 contexts)
   at Machine.Specifications.Runner.Impl.DefaultRunner.StartRun(IDictionary`2 contextMap)
   at Machine.Specifications.Runner.Impl.DefaultRunner.RunClass(MemberInfo member, Assembly assembly)
   at Machine.Specifications.Runner.Impl.DefaultRunner.RunMember(Assembly assembly, MemberInfo member)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [1]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Machine.Specifications.Runner.ISpecificationRunner.RunMember(Assembly assembly, MemberInfo member)
   at Machine.Specifications.Runner.Impl.AppDomainRunner.RunMember(Assembly assembly, MemberInfo member)
   at Machine.Specifications.ReSharperRunner.Runners.RecursiveMSpecTaskRunner.RunContext(ISpecificationRunner runner, Assembly contextAssembly, TaskExecutionNode node)
   at Machine.Specifications.ReSharperRunner.Runners.RecursiveMSpecTaskRunner.ExecuteRecursive(TaskExecutionNode node)
   at JetBrains.ReSharper.TaskRunnerFramework.StartupTaskRunnerHost.Execute(TaskExecutionNode node)

所有测试都标记为Inconclusive,R#会话窗口中没有任何内容告诉我发生了什么。我试图创建一个repo解决方案,但一直无法这样做。我可以单步执行代码并手动找出异常,但显然弹出这个代码会使调试变得更加困难。是什么导致序列化?它似乎创建了一个新的AppDomain,但是我无法在创建的appdomain上为Resolve Load挂接任何事件。 Fusion日志显示它正在寻找我在R#安装文件夹中测试的程序集。禁用卷影副本也不会对此产生任何影响。

有什么想法吗?我正在使用NuGet的最新Moq和MSpec。

更新:抛出异常并不重要;如果因为完成而没有异常,我会看到相同的行为,但是没有执行任何It语句。

1 个答案:

答案 0 :(得分:1)

Mspec为每个正在测试的程序集创建一个新的AppDomain,主要是为了支持dll.config文件。作为副作用,规范程序集和运行程序之间传递的所有数据都必须序列化(远程执行)。某些将遍历AppDomain边界的类型未使用SerializableAttribute标记,因此是例外。

我想这可能是一个自定义异常或该异常的成员,因为这是我能想到的唯一类型,它将跨越AppDomain边界。 (Mspec的内部类型都是可序列化的。)