System.NotSupportedException in TaskScheduler when using PublishTrimmed .NET6.0

Viewed 798

I want to use TaskScheduler using "TaskScheduler 1.1 Type Library" from Add COM Reference.

using TaskScheduler;
...
     ITaskService taskservice = null;
     taskservice = new TaskScheduler.TaskScheduler(); <=NotSupportedException
     taskservice.Connect(null, null, null, null);

But the above code will cause an exception.

System.NotSupportedException: 'Built-in COM has been disabled via a feature switch. See https://aka.ms/dotnet-illink/com for more

If PublishTrimmed is set to false, no exception will be raised. However, I don't want to set it to false because it will increase the size of the exe.

project file is following

 <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>false</SelfContained>
    <PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

I try to add assembly to TrimmerRootAssembly. But following is not worked.

<ItemGroup>
    <TrimmerRootAssembly Include="TaskScheduler" />
    <TrimmerRootAssembly Include="Microsoft.Win32.TaskScheduler" />
</ItemGroup>
1 Answers
Related