question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization issue with AppDomains and some dlls (e.g. log4net)

See original GitHub issue

Description

Sometimes MSTest fails with ‘Unable to find assembly’ when searching for a nuget package dll

Steps to reproduce

  1. Load the project
  2. Execute TestMethodLog4Net1

Expected behavior

The project should always be able to find the log4net assembly and load it

Actual behavior

Sometimes MSTest is not able to find the assembly. The problem can be (sometimes) worked around by installed previous versions of MSTest.TestAdapter which will then show the following line:

Multiple versions of same extension found. Selecting the highest version.

But uninstalling the package MSTest.TestAdapter and reinstalling it will bring back the bug.

This is the stacktrace output:

Log level is set to Informational (Default).
Source code repository not available. Some features may not work as expected.
Connected to test environment '< Local Windows Environment >'
Test data store opened in 0,123 sec.
========== Starting test discovery ==========
========== Test discovery skipped: All test containers are up to date ==========
Building Test Projects
========== Starting test run ==========
An exception occurred while invoking executor 'executor://mstestadapter/v2': Unable to find assembly 'log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.
Stack trace:

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.SmuggledMethodReturnMessage.FixupForNewAppDomain()
   at System.Runtime.Remoting.Channels.CrossAppDomainSink.SyncProcessMessage(IMessage reqMsg)

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 Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.UnitTestRunner.RunSingleTest(TestMethod testMethod, IDictionary`2 testContextProperties)
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsWithTestRunner(IEnumerable`1 tests, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, String source, IDictionary`2 sourceLevelParameters, UnitTestRunner testRunner)
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTestsInSource(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, String source, Boolean isDeploymentDone)
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.ExecuteTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, Boolean isDeploymentDone)
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestExecutionManager.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle, TestRunCancellationToken runCancellationToken)
   at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithTests.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUri, RunContext runContext, IFrameworkHandle frameworkHandle)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass46_0.<RunTestInternalWithExecutors>b__0()
   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInStaThread(Action action, Boolean waitForCompletion)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)

========== Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in 1,1 sec ==========

A PoC can be found in https://github.com/elgatov/BugMSTest

Environment

Windows 10 Enterprise N v1809 17763.1935 Test Execution Command Line Tool Version 17.3.0-preview-20220626-01 (x64) Autofac v6.4.0 coverlet.collector v3.1.2 log4net v2.0.15 Microsoft.NET.Test.Sdk v17.3.0 MSTest.TestAdapter v2.2.10 MSTest.TestFramework v2.2.10

AB#1658514

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mike-loux-planviewcommented, Nov 21, 2022

Hi @mike-loux-planview, thanks for the bump. I will need to do more investigation to understand exactly what’s causing the issue before being able to provide a fix or workaround as I only did a shallow search so far and directly stumbled upon the fact that the serialization issue could be linked to app domains.

Let me reopen the issue (but I will have to remove the milestone because my bandwidth is a little short).

Thanks, @Evangelink! I understand all too well about short bandwidth. Appreciate you taking the time (however small or long) to look into this some more.

1reaction
Evangelinkcommented, Nov 21, 2022

Hi @mike-loux-planview, thanks for the bump. I will need to do more investigation to understand exactly what’s causing the issue before being able to provide a fix or workaround as I only did a shallow search so far and directly stumbled upon the fact that the serialization issue could be linked to app domains.

Let me reopen the issue (but I will have to remove the milestone because my bandwidth is a little short).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration system failed to initialize: Type is not ...
The error still exist. I already tried lowering the version of log4net but didn't work. I've been looking around but fail to find...
Read more >
Solved: Binding context - log4net DLL
The assembly with display name 'log4net' failed to load in the 'Load' binding context of the AppDomain with ID 7.
Read more >
Tests not running with "Type is not resolved for member... ...
Changed the code, to make sure that on TestCleanup the CallContext is cleared (and so no object needs to be serialized between App...
Read more >
Apache log4net: Release Notes
Apache log4net 2.0.14 is a minor release to address some reported issues and ... [LOG4NET-178] - Log4Net stops logging after appdomain recycle of...
Read more >
log4net 1.2.0 Beta 8 - Release Notes
Changed assembly name to log4net. The build output is now log4net.dll for all frameworks. This is a breaking change. To resolve cross platform...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found