From a5b240d164998280089b0f05af729f85b924d715 Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko Date: Thu, 28 Sep 2023 13:04:41 +0300 Subject: [PATCH] Negotiate the mismatch major version in assembly binding for legacy runtime --- .../ReportPortalLogger.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs b/src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs index f4d64ac..69c344f 100644 --- a/src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs +++ b/src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs @@ -36,6 +36,21 @@ public class ReportPortalLogger : ITestLoggerWithParameters public ReportPortalLogger() { +# if NETFRAMEWORK + // Negotiate "Comparing the assembly name resulted in the mismatch: Major Version" assembly binding issue for legacy runtime + AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => + { + var assemblyName = new System.Reflection.AssemblyName(args.Name).Name; + var assemblyFileName = Path.Combine(Path.GetDirectoryName(new Uri(typeof(ReportPortalLogger).Assembly.Location).LocalPath), $"{assemblyName}.dll"); + + if (File.Exists(assemblyFileName)) + { + return System.Reflection.Assembly.LoadFrom(assemblyFileName); + } + + return null; + }; +#endif var testLoggerDirectory = Path.GetDirectoryName(new Uri(typeof(ReportPortalLogger).Assembly.CodeBase).LocalPath); TraceLogger = TraceLogManager.Instance.WithBaseDir(testLoggerDirectory).GetLogger(typeof(ReportPortalLogger)); @@ -54,6 +69,7 @@ public ReportPortalLogger() _statusMap[TestOutcome.NotFound] = Status.Skipped; } + /// /// Initializes the Test Logger. /// @@ -217,7 +233,7 @@ private void Events_TestResult(object sender, TestResultEventArgs e) } // find categories - var testCategories = new List (); + var testCategories = new List(); var traits = e.Result.TestCase.Traits.ToList(); if (e.Result.TestCase.ExecutorUri.ToString().ToLower().Contains("mstest")) @@ -251,7 +267,7 @@ private void Events_TestResult(object sender, TestResultEventArgs e) if (traits.Any() && startTestRequest.Attributes == null) startTestRequest.Attributes = new List(); foreach (var itemAttribute in traits.Select(x => new ItemAttribute - { Key = x.Name, Value = x.Value })) + { Key = x.Name, Value = x.Value })) startTestRequest.Attributes.Add(itemAttribute); var testReporter = suiteReporter.StartChildTestReporter(startTestRequest);