BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Attempting to run on mono.exe shipped with Unity game engine. `CS1069: The type name 'Console' could not be found in the namespace 'System'.`

Open Aidiakapi opened this issue 3 years ago • 3 comments

I've been attempting to run some pure C# performance tests, but using the version of mono.exe and the BCL shipping with the Unity game engine.

However, after trying a lot of different ways to get it to run, it keeps showing these errors:

CS1069: The type name 'Console' could not be found in the namespace 'System'. This type has been forwarded to assembly 'System.Console, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
CS1069: The type name 'Console' could not be found in the namespace 'System'. This type has been forwarded to assembly 'System.Console, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
CS1503: Argument 2: cannot convert from 'System.Text.Encoding' to 'bool'
CS1069: The type name 'Enumerable' could not be found in the namespace 'System.Linq'. This type has been forwarded to assembly 'System.Linq, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
CS1069: The type name 'Enumerable' could not be found in the namespace 'System.Linq'. This type has been forwarded to assembly 'System.Linq, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
CS1069: The type name 'Enumerable' could not be found in the namespace 'System.Linq'. This type has been forwarded to assembly 'System.Linq, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

This is the configuration used:

	public class UnityMonoConfig : ManualConfig
	{
		public UnityMonoConfig() {
			WithOption(ConfigOptions.KeepBenchmarkFiles, true);
			var job = Job.Dry.WithRuntime(new MonoRuntime(
				"Mono x64",
				@"M:\Unity\Data\MonoBleedingEdge\bin\mono.exe",
				null,
				@"M:\Unity\Data\MonoBleedingEdge\lib\mono\unityjit-win32"
			));
			AddJob(job);
		}
	}

It is with Unity engine version 2021.2. It seems to be tangentially related to #1390 and #1392, however, the remedy of switching the test project itself to .NET 4.x does not work, since these projects are on netstandard2.1, which is not supported. Instead the test runner project is running on .NET 5, with the tested project being aforementioned netstandard2.1.

I've tried adding NuGet references, but the RoslynToolchain does not support that, switching to different toolchains either does not work, or in case of the InProcessEmit toolchains, they do not actually run Mono.

When inspecting the Dry.bat, I can see that it's referencing various .dll's from .NET 5: /reference:"C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Runtime.dll","C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Collections.dll"

However, that should be fine, since it's only compiling the benchmark code, and I don't think that's where it trips up.

I've tried adding various references to the test runner project, but nothing seems to help, this is the project:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <LangVersion>9</LangVersion>
        <OutputType>Exe</OutputType>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
      <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      </PackageReference>
      <PackageReference Include="System.Console" Version="4.3.1" />
      <PackageReference Include="System.Linq" Version="4.3.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\Shared.Core\Shared.Core.csproj" />
    </ItemGroup>

</Project>

What should I do to get this to work?

Aidiakapi avatar Nov 12 '21 12:11 Aidiakapi

I hit this issue, and found that changing the <TargetFramework> of the test runner project from net5.0 to net471 fixed it.

tgjones avatar Feb 04 '22 17:02 tgjones

Sadly this is not an option with the later Unity versions :/.

remedy of switching the test project itself to .NET 4.x does not work, since these projects are on netstandard2.1, which is not supported

Aidiakapi avatar Feb 09 '22 15:02 Aidiakapi

I've also hit this issue today this has been a blocker for benchmarking some code for unity for me

mdsitton avatar May 15 '22 07:05 mdsitton

Got it to run by compiling first and then running with mono - see https://github.com/dotnet/BenchmarkDotNet/issues/1390#issuecomment-597652626 - this way can run the net471 TargetFramework version by running mono bench.exe.

Still trying to figure out how to run a netstandard2.0 version with mono - as it produces a bench.dll.

mastef avatar Apr 12 '23 04:04 mastef