gpt4 book ai didi

exception - 如何使用 Vstest.console.exe 和 Moq 避免 SerializationException 警告

转载 作者:行者123 更新时间:2023-12-03 07:45:10 25 4
gpt4 key购买 nike

我有一个 .NET 3.5 项目以及相应的单元测试项目。

首先,自从更新到 VS 2013 以来,我无法再使用 MSTest 运行测试项目。我了解到 vstest.console.exe 是执行测试的新首选方式。

尽管如此,在使用 vstest.console.exe 执行 550 个单元测试(全部成功)的测试运行期间,我的控制台收到了很多此类异常的垃圾邮件:

Warning: System.Runtime.Serialization.SerializationException: Unable to find assembly 'Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920'.
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.ObjectMap.Create(String name, 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.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
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.AppDomain.Deserialize(Byte[] blob)
at System.AppDomain.UnmarshalObject(Byte[] blob)
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.ObjectMap.Create(String name, 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.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)
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.AppDomain.Deserialize(Byte[] blob)
at System.AppDomain.UnmarshalObject(Byte[] blob)

我不知道我做错了什么。我只能猜测,因为测试是在隔离模式下执行的(可能是因为 .NET Framework 3.5),所以需要在应用程序域之间传输一些对象,而这里会发生这些异常。

我的问题是:为什么找不到程序集? Moq.dll 就在我的单元测试程序集旁边。我该如何防止测试运行期间出现数百条异常消息?

更新:

我被要求同时运行融合记录器,它给了我以下信息:

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.clr20.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: Moq, Version=4.2.1402.2112, Culture=neutral, PublicKeyToken=69f491c39445e920
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Moq.DLL.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Moq/Moq.DLL.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/Moq.DLL.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/Moq/Moq.DLL.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Moq.EXE.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Moq/Moq.EXE.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/Moq.EXE.
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 12.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/Moq/Moq.EXE.
LOG: All probing URLs attempted and failed.

现在,我问为什么它不使用我的测试项目提供的程序集。我无法将 Moq.dll 复制到这些路径中的任何一个,因为我在同一测试运行中运行多个测试项目,这些项目使用某些程序集的不同版本,并且我只能在此处提供一个特定版本。

最佳答案

我在构建机器上收到类似的警告。原因原来是在单元测试执行期间抛出 MockExceptions(即使在我的情况下,所有测试都成功,因为 async-await 怪异)。

识别这些异常的技巧是“调试”单元测试而不是“运行”(右键单击并选择在项目级别调试选定的测试)。修复这些 MockExceptions 消除了我的构建警告。希望这会有所帮助。

关于exception - 如何使用 Vstest.console.exe 和 Moq 避免 SerializationException 警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24675922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com