I am trying to port C# Interop code for all Office apps (Outlook,Excel,Word,PowerPoint,etc) from NET Framework 4.8 to NET 5.0. But I am being blocked by the removal of Marshall.GetActiveObject
from the NET 5 Marshal.* API.
Installing the package Microsoft.Windows.Compatibility did not help. Here is an example of code that used to work, but now fails for all apps.
var o = Marshal.GetActiveObject("Access.Application") as Access.Application;
var o = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
var o = Marshal.GetActiveObject("Word.Application") as Word.Application;
var o = Marshal.GetActiveObject("Powerpoint.Application") as Excel.Application;
Can anyone please tell me how to access running instances of these apps under NET 5? I imagine that the Microsoft developers would not have removed the API without providing some (hopefully recommended) way of accessing running apps. Thank you