MissingMethodException when using `net462` via mono on linux
Build and run this project on linux:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net472;net48</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PolySharp" Version="1.15.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="TUnit" Version="0.73.19" />
</ItemGroup>
</Project>
class Tests
{
[Test]
public Task TestMethod()
{
return Task.CompletedTask;
}
}
net472 and net48 work fine.
The tests for net462 all fail to run with this error:
TUnit v0.73.19.0 | 64-bit | Unix 6.6.87.2 | .NET Framework | Mono 6.12.0 (makepkg/0cbf0e290c3 Sat Mar 9 11:37:33 UTC 2024) | Microsoft Testing Platform v2.0.1
failed TestMethod (0ms)
TUnit.Engine.Exceptions.TestFailedException: InvalidOperationException: Failed to expand data source for test 'TestMethod': Failed to initialize data source of type 'NoDataSource': Method not found: System.ValueTuple`2<System.Reflection.PropertyInfo, TUnit.Core.IDataSourceAttribute>[] TUnit.Core.PropertyInjection.PropertyInjectionPlan.get_ReflectionProperties()
---> System.InvalidOperationException: Failed to initialize data source of type 'NoDataSource': Method not found: System.ValueTuple`2<System.Reflection.PropertyInfo, TUnit.Core.IDataSourceAttribute>[] TUnit.Core.PropertyInjection.PropertyInjectionPlan.get_ReflectionProperties()
at TUnit.Engine.Services.DataSourceInitializer.InitializeDataSourceAsync (System.Object dataSource, System.Collections.Generic.Dictionary`2[TKey,TValue] objectBag, TUnit.Core.MethodMetadata methodMetadata, TUnit.Core.TestContextEvents events) [0x001ee] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Services.DataSourceInitializer.EnsureInitializedAsync[T] (T dataSource, System.Collections.Generic.Dictionary`2[TKey,TValue] objectBag, TUnit.Core.MethodMetadata methodMetadata, TUnit.Core.TestContextEvents events) [0x000f6] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder+<GetInitializedDataRowsAsync>d__13.MoveNext () [0x000f6] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[TResult].GetResult (System.Int16 token) [0x0001f] in <27ea3691bd5a48e4bc6bea4b94ec80a6>:0
at TUnit.Engine.Building.TestBuilder+<GetInitializedDataRowsAsync>d__13.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (System.Int16 token) [0x00000] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder.BuildTestsFromMetadataAsync (TUnit.Core.TestMetadata metadata) [0x01098] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder.BuildTestsFromMetadataAsync (TUnit.Core.TestMetadata metadata) [0x01140] in <970716ffdc15408cbe05af0b81ab3ca8>:0
---> System.InvalidOperationException: Failed to initialize data source of type 'NoDataSource': Method not found: System.ValueTuple`2<System.Reflection.PropertyInfo, TUnit.Core.IDataSourceAttribute>[] TUnit.Core.PropertyInjection.PropertyInjectionPlan.get_ReflectionProperties()
at TUnit.Engine.Services.DataSourceInitializer.InitializeDataSourceAsync (System.Object dataSource, System.Collections.Generic.Dictionary`2[TKey,TValue] objectBag, TUnit.Core.MethodMetadata methodMetadata, TUnit.Core.TestContextEvents events) [0x001ee] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Services.DataSourceInitializer.EnsureInitializedAsync[T] (T dataSource, System.Collections.Generic.Dictionary`2[TKey,TValue] objectBag, TUnit.Core.MethodMetadata methodMetadata, TUnit.Core.TestContextEvents events) [0x000f6] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder+<GetInitializedDataRowsAsync>d__13.MoveNext () [0x000f6] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore`1[TResult].GetResult (System.Int16 token) [0x0001f] in <27ea3691bd5a48e4bc6bea4b94ec80a6>:0
at TUnit.Engine.Building.TestBuilder+<GetInitializedDataRowsAsync>d__13.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (System.Int16 token) [0x00000] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder.BuildTestsFromMetadataAsync (TUnit.Core.TestMetadata metadata) [0x01098] in <970716ffdc15408cbe05af0b81ab3ca8>:0
at TUnit.Engine.Building.TestBuilder.BuildTestsFromMetadataAsync (TUnit.Core.TestMetadata metadata) [0x01140] in <970716ffdc15408cbe05af0b81ab3ca8>:0
I have tested older versions. This error first occurred in v0.63.0. Older builds of TUnit used to work.
I'm using Arch via WSL in case that makes a difference.
(If you try to test this in WSL, make sure to install mono. Otherwise, WSL will run the test exe in the host system instead of the VM)
Does adding https://www.nuget.org/packages/system.valuetuple/ solve it?
No, it doesn't seem to make a difference. I also tried that with the workaround for https://github.com/dotnet/sdk/issues/51265 and it doesn't work.
The SDK version also doesn't make a difference (I tried 8.0.415, 9.0.306, and 10.0.100-rc.2.25502.107)
I think this might be caused by https://github.com/dotnet/sdk/issues/51265 in your repo.
Should hopefully fix itself in a week or two then when the new version is officially out!
This workaround works for me, using .NET 10 RC2, put this in Directory.Build.targets:
<PropertyGroup>
<RestoreEnablePackagePruning Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' "> false</RestoreEnablePackagePruning>
</PropertyGroup>
@sliekens I'm already doing that. Doesn't help. https://github.com/PhilippNaused/Bshox/blob/f4ac90aa970cbe482590e224e4a22327525e32c9/Directory.Build.targets#L7-L9 I assume the bug affects this repo when TUnit is built. So adding it to my repo alone doesn't fix it. We need to wait for a build of TUnit compiled with .NET 10 (no prerelease) to be sure.
@PhilippNaused have you tried with Polyfill instead of PolySharp? I remember I had some issues with that. I'm running latest TUnit on Linux with Mono for net481 targets and it works (in combination with .NET 10 RC2 SDK).
@sliekens Yes, I have tried that. It doesn't make a difference. This bug only affects net462, not any newer version of the framework.
If you define ModuleInitializerAttribute manually in your code, you don't need either poly package to reproduce this issue.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
<TargetFrameworks>net462;net472;net48</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TUnit" Version="1.0.30" />
</ItemGroup>
</Project>
class Tests
{
[Test]
public Task TestMethod() => Task.CompletedTask;
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
internal sealed class ModuleInitializerAttribute : Attribute;
}
dotnet run -f net472 works, but dotnet run -f net462 gives the exception.
v1.0.78 is out and built using the new .NET 10 SDK. Any chance it fixed it?
No, unfortunately I can still reproduce it in v1.0.78 ☹️
Dang :(
It sounds like something out of my control unfortunately 🫤
It might be a bug in mono. Like some kind of incompatibility with newer C# features (wouldn't be the first time).