dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.2k stars 191 forks source link

Support COM Wrappers #948

Closed AigioL closed 2 years ago

AigioL commented 2 years ago

Is your feature request related to a problem? Please describe. Built-in COM incompatibilities trim https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options

Describe the solution you'd like https://docs.microsoft.com/en-us/dotnet/standard/native-interop/com-wrappers Maybe you can refer to these changes https://github.com/dotnet/runtime/pull/54884

Additional context

System.TypeInitializationException: The type initializer for 'Microsoft.Win32.TaskScheduler.TaskService' 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 Microsoft.Win32.TaskScheduler.TaskService.Connect()
   at Microsoft.Win32.TaskScheduler.TaskService..ctor()
   at Microsoft.Win32.TaskScheduler.TaskService.get_Instance()
   at Microsoft.Win32.TaskScheduler.TaskService..cctor()
dahall commented 2 years ago

It is impossible to disable COM for this library since it is a wrapper for the COM-based API for the Windows Task Scheduler from Microsoft.

peterhorsley commented 1 month ago

You may be able to overcome this error by adding

<BuiltInComInteropSupport>true</BuiltInComInteropSupport>

to your PropertyGroup in your csproj file. If you are using PublishTrimmed, you will also need to add

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

See https://stackoverflow.com/questions/68110207/system-notsupportedexception-in-taskscheduler-when-using-publishtrimmed-net6-0