Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xunit.V2] Xunit Mismatch on mono sdk #3152

Open
saitama951 opened this issue Jan 31, 2025 · 1 comment
Open

[Xunit.V2] Xunit Mismatch on mono sdk #3152

saitama951 opened this issue Jan 31, 2025 · 1 comment

Comments

@saitama951
Copy link

saitama951 commented Jan 31, 2025

on Mono SDK,

[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type of field 'Xunit.ConsoleClient.ConsoleRunner:completionMessages' (3) due to: Could not load file or assembly 'xunit.runner.utility.netcoreapp10, Version=2.4.2.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c' or one of its dependencies.

the runtime test's fails with the above error.

see for details: dotnet/runtime#60550

TL;DR:
https://github.com/xunit/xunit/blob/v2/src/xunit.console/Program.cs

namespace Xunit.ConsoleClient
{
    public class Program
    {
        [STAThread]
        public static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            // This code must not contain any references to code in any external assembly (or any code that references any code in any
            // other assembly) until AFTER the creation of the AssemblyHelper.
            var consoleLock = new object();
            var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(consoleLock, args.Contains("-internaldiagnostics"), args.Contains("-nocolor"));

            using (AssemblyHelper.SubscribeResolveForAssembly(typeof(Program), internalDiagnosticsMessageSink))
                return new ConsoleRunner(consoleLock).EntryPoint(args);
        }
    }
}

When Mono JIT compiles Main(), it encounters a call to new ConsoleRunner() . Unlike CoreCLR, Mono JIT attempts to resolve all field types of ConsoleRunner at JIT compilation time, rather than deferring resolution until runtime.
The problem arises because some fields inside ConsoleRunner depend on assemblies that are only resolvable via the assembly resolve event handler. However, this resolve handler is only installed after Main() has been compiled and execution starts. As a result, Mono JIT fails when it attempts to load these types too early, leading to runtime errors.

This would be a workaround for the mono JIT's limitation

I have provided a similar fix in dotnet/arcade: dotnet/arcade#15467

I think having a similar fix in xunit.v2 would be a good idea as well, I would like to know your thoughts on this?

@bradwilson
Copy link
Member

We don't officially support Mono w/ xUnit.net v2. Additionally, there are no plans for any further v2 releases.

You're welcome to submit a PR and we will leave it open in the event that there is another v2 release, but this would not meet the bar to issue a new release, since Mono isn't officially supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants