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

TaskbarProgressCom is not supported when benchmarking Native AOT #2253

Closed
3steve3 opened this issue Jan 20, 2023 · 10 comments · Fixed by #2255
Closed

TaskbarProgressCom is not supported when benchmarking Native AOT #2253

3steve3 opened this issue Jan 20, 2023 · 10 comments · Fixed by #2255
Milestone

Comments

@3steve3
Copy link

3steve3 commented Jan 20, 2023

It appears that https://github.com/dotnet/BenchmarkDotNet/blob/master/src/BenchmarkDotNet/Helpers/Taskbar/TaskbarProgress.cs is using COM Interop, and it not supported by default when using Native AOT.

The output that I'm getting is:

Unhandled exception. System.TypeInitializationException: The type initializer for 'BenchmarkDotNet.Helpers.TaskbarProgressCom' threw an exception.
 ---> System.NotSupportedException: Built-in COM has been disabled via a feature switch. See https://aka.ms/dotnet-illink/com for more information.
   at BenchmarkDotNet.Helpers.TaskbarProgressCom..cctor()
   --- End of inner exception stack trace ---
   at BenchmarkDotNet.Helpers.TaskbarProgressCom.SetState(IntPtr consoleWindowHandle, IntPtr consoleHandle, TaskbarProgressState taskbarState)
   at BenchmarkDotNet.Running.BenchmarkRunnerClean.Run(BenchmarkRunInfo[] benchmarkRunInfos)
   at BenchmarkDotNet.Running.BenchmarkSwitcher.RunWithDirtyAssemblyResolveHelper(String[] args, IConfig config, Boolean askUserForInput)
   at BenchmarkDotNet.Running.BenchmarkSwitcher.Run(String[] args, IConfig config)
   at MyBenchmarks.Program.Main(String[] args) in C:\Users\Steve\source\repos\BenchmarkTesting\BenchmarkTesting\Program.cs:line 102
@adamsitnik
Copy link
Member

Hi @3steve3

How do you run your benchmarks?

I would expect your host process (what you start from command line) to be non-NativeAOT and work fine, while the benchmark process that does not use the taskbar be NativeAOT and also work fine.

@3steve3
Copy link
Author

3steve3 commented Jan 20, 2023

@adamsitnik I'm using this command dotnet run -c Release -f net7.0 --runtimes nativeaot7.0 and this main static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

@adamsitnik
Copy link
Member

Based on https://stackoverflow.com/questions/68110207/system-notsupportedexception-in-taskscheduler-when-using-publishtrimmed-net6-0 I suspect that something sets PublishTrimmed to true for your project with benchmarks. Could you please try setting <BuiltInComInteropSupport>true</BuiltInComInteropSupport> as described in https://stackoverflow.com/a/69200541/5852046 for the benchmarks project?

If it does not help could you please try downloading our samples and running them?

git clone https://github.com/dotnet/BenchmarkDotNet.git
cd .\BenchmarkDotNet\samples\BenchmarkDotNet.Samples\
dotnet run -c Release -f net7.0 --filter *Basic*Sleep* --runtimes nativeaot7.0

it works fine on my machine:

image

@timcassell
Copy link
Collaborator

I was able to repro by adding <BuiltInComInteropSupport>false</BuiltInComInteropSupport>. Unfortunately, the TypeInitializationException seems to be uncatchable, so I'm trying to figure out another fix.

@timcassell
Copy link
Collaborator

@adamsitnik Fixed in #2255.

@eerhardt
Copy link
Member

I hit the same issue in my csproj:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
  </ItemGroup>

</Project>

Worked around it by commenting out the <PublishAot>true</PublishAot> line.

@AndreyAkinshin AndreyAkinshin added this to the v0.14.0 milestone Jul 20, 2024
@ygoe
Copy link

ygoe commented Jul 26, 2024

Seriously? You "fix" the bug by not doing what you originally wanted to do? Is BenchmarkDotNet even compatible with AOT? How can I proceed with this exception? I really don't care about taskbar progress. I just want to run realistic benchmarks. Maybe I'll have to run my own Stopwatch loop again. It wasn't that bad last time. Actually I was also interested in memory consumption results.

@timcassell
Copy link
Collaborator

timcassell commented Jul 26, 2024

@ygoe What do you mean? Did you try the nightly build with the fix?

@ygoe
Copy link

ygoe commented Jul 27, 2024

What I mean is: My application runs with PublishAOT and I'd like to benchmark two possible implementations of something I want to do in there. To get realistic results, I'm interested in the benchmark running the AOT-compiled code, not the JITed code.

I'm running this from Visual Studio in Release mode. It opens by default in the Windows Terminal app here on Windows 11.

I've used the public NuGet package.

@timcassell
Copy link
Collaborator

The fix is not on public nuget yet. You will need to use the nightly version to get the fix. https://benchmarkdotnet.org/articles/guides/nuget.html#nightly

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

Successfully merging a pull request may close this issue.

6 participants