-
I have a minimal repro/sample .NET 6 project that is based off the documentation for using background tasks in packaged winmain applications. When I deploy this package on Windows 11, the COM background task is registered with the system and configured to repeatedly invoke the CLSID background task at 15-minute intervals. The background task is successfully registered with the system (thanks to the appx manifest) and the SystemTimer trigger correctly fires periodically. The sample application is launched with the specified command-line arguments, and it starts up the COM server to service the activation via instantiation of an IClassFactory. Windows accepts the created IClassFactory instance and then calls However, after this point Windows never actually uses the I've attached the minimal reproduction to this issue. I'm using the latest released WindowsAppSdk 1.0.3 and .NET 6 - note that the documentation on winmain background tasks above is actually incorrect and inadequate as it relies on .NET Framework features not in .NET Core/.NET 5+ and contains typos that would prevent it from even compiling. In the attached sample project, a log file is kept in the package's |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi Mahmoud, I took a look at your sample and observed the same issue you reported in a local repro. From some COM diagnostics logging, I found that 0x80020001 (looks like a DISP_E_UNKNOWNINTERFACE/E_NOINTERFACE) was being returning when attempting to invoke the Run method for your BG task object. I suspect your manual implementation of ClassFactory.CreateInstance (and its use of Marshal.GetComInterfaceForObject) may not be exactly what the system expects the COM pointer to be when the system tries to invoke the Run method. I haven't been able to root cause what where the mentioned error code is coming from yet. However, in the meantime you can take a look at the public end-to-end samples that are written in both C++/WinRT and C# (although it uses full .NET) here: https://github.com/microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/BackgroundTaskWinMainComSample These samples have been tested on Windows 11. You can run the background task and debug it following the instructions from the page. Please do follow up if you ended up figuring out what resolved your issue. Best Regards, |
Beta Was this translation helpful? Give feedback.
-
Hi Arup, Thanks for taking a look! I assumed that much, but that's code that was working fine for me for interoping with COM types. It turns out I was running into a fundamental limitation of .NET 5+ where most COM-interop code was stripped from the language/compiler, so those projects weren't of any use. Basic The solution is found in this document that explains how to migrate COM interop code to .NET 5. I had to replace ppvObject = MarshalInterface<TInterface>.FromManaged(new T()); which seems to work fine! |
Beta Was this translation helpful? Give feedback.
-
Hi Mahmoud, Thank you for the follow up! We'll ensure your solution is incorporated into samples demonstrating background tasks with .NET Core. Arup |
Beta Was this translation helpful? Give feedback.
-
@aruproy14 I opened sourced the code and published it to GitHub here: https://github.com/mqudsi/BackgroundTask I cleaned it up and added a lot of documentation; I also made the core com registration class completely reusable. |
Beta Was this translation helpful? Give feedback.
-
@aruproy14 i tested out the C++ background task sample, and the task is never called, i filed this issue, but it hasn't had any traction: microsoft/DesktopBridgeToUWP-Samples#119 |
Beta Was this translation helpful? Give feedback.
Hi Arup,
Thanks for taking a look! I assumed that much, but that's code that was working fine for me for interoping with COM types. It turns out I was running into a fundamental limitation of .NET 5+ where most COM-interop code was stripped from the language/compiler, so those projects weren't of any use. Basic
IUnknown
support remains, which is why the code worked for me in other projects, butIBackgroundTask
seems to require more than just that for the CCW to work.The solution is found in this document that explains how to migrate COM interop code to .NET 5. I had to replace
Marshal.GetComInterfaceForObject
with the new WASDK-providedMarshalInterface<T>.FromManaged(...)
so the line no…