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

Open
3steve3 opened this issue Jan 20, 2023 · 6 comments · May be fixed by #2255
Open

TaskbarProgressCom is not supported when benchmarking Native AOT #2253

3steve3 opened this issue Jan 20, 2023 · 6 comments · May be fixed by #2255

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 timcassell linked a pull request Jan 20, 2023 that will close this issue
@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.

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.

4 participants