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

Targeting .NET 6 seems to trigger exception in some odd circumstances #1638

Open
CptWesley opened this issue Jan 21, 2025 · 2 comments · May be fixed by #1642
Open

Targeting .NET 6 seems to trigger exception in some odd circumstances #1638

CptWesley opened this issue Jan 21, 2025 · 2 comments · May be fixed by #1642

Comments

@CptWesley
Copy link

Previous project setup where -> denotes a dependency:

project A;
project A.SourceGenerator;
project A.Tests;

project A -> project A.SourceGenerator;
project A.Tests -> TUnit;
project A.Tests -> A;

The tests worked perfectly fine when A.Tests targeted both net6.0 and net9.0.

Now I introduced another source generator:

project A;
project A.SourceGenerator;
project A.AnotherSourceGenerator;
project A.Tests;

project A -> project A.SourceGenerator;
project A -> project A.AnotherSourceGenerator;
project A.Tests -> TUnit;
project A.Tests -> A;

The new source generator does not generate any code that is hit by any tests in A.Tests and works fine when targeting net9.0 (as one would expect, since from the A.Tests perspective, nothing really changed), but when targeting net6.0 we suddenly run into the following exception:

Unhandled exception. System.MissingMethodException: Method not found: 'Void Microsoft.Testing.Platform.Extensions.Messages.TestNode.set_DisplayName(System.String)'.
   at TUnit.Engine.Framework.TUnitTestFramework.ExecuteRequestAsync(ExecuteRequestContext context)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at TUnit.Engine.Framework.TUnitTestFramework.ExecuteRequestAsync(ExecuteRequestContext context)
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteRequestAsync(ITestFramework testFramework, TestExecutionRequest request, IMessageBus messageBus, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 73
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteAsync(ITestFramework testFramework, ClientInfo client, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 62
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.ExecuteRequestAsync(IPlatformOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 111
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 84
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 116
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 85
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 33
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 56
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 240

I did some digging in the code of TestNode.cs and TUnitTestFramework, but didn't find anything strange. The tests output that the detected testing platform version is 1.4.3, which defines the init prop DisplayName on TestNode, which should result in a hidden set_DisplayName(string) method, so I don't really understand how it can not find the method (or why this was not an issue previously or when targeting net9.0).

@thomhurst thomhurst linked a pull request Jan 21, 2025 that will close this issue
@thomhurst
Copy link
Owner

Yeah this is weird! I can replicate it too if I target .NET 6 on the build pipeline.

I've raised with the MS Testing platform team, so let's see what they say.

@thomhurst
Copy link
Owner

Seems to be a Testing Platform bug that they've identified apparently

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

Successfully merging a pull request may close this issue.

2 participants