Skip to content

Commit

Permalink
Negotiate the mismatch major version in assembly binding for legacy r…
Browse files Browse the repository at this point in the history
…untime
  • Loading branch information
nvborisenko committed Sep 28, 2023
1 parent 4e60f7e commit a5b240d
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ReportPortal.VSTest.TestLogger/ReportPortalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -54,6 +69,7 @@ public ReportPortalLogger()
_statusMap[TestOutcome.NotFound] = Status.Skipped;
}


/// <summary>
/// Initializes the Test Logger.
/// </summary>
Expand Down Expand Up @@ -217,7 +233,7 @@ private void Events_TestResult(object sender, TestResultEventArgs e)
}

// find categories
var testCategories = new List<string> ();
var testCategories = new List<string>();
var traits = e.Result.TestCase.Traits.ToList();

if (e.Result.TestCase.ExecutorUri.ToString().ToLower().Contains("mstest"))
Expand Down Expand Up @@ -251,7 +267,7 @@ private void Events_TestResult(object sender, TestResultEventArgs e)
if (traits.Any() && startTestRequest.Attributes == null)
startTestRequest.Attributes = new List<ItemAttribute>();
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);
Expand Down

0 comments on commit a5b240d

Please sign in to comment.