I've been unable to get the Microsoft.Office.Interop.Outlook library to work the way I need it to in .NET Core, but it works fine in .NET Framework. As a result I want to build my main application as a .NET Core project, and only call the .NET Framework part as needed (from another project within the same solution).
So I've got my .Net Framework project, let's call it TESTOutlookInterop. It's got one class that looks like this:
using Microsoft.Office.Interop.Outlook;
namespace TESTOutlookInterop
{
public class OutlookInterop
{
public string GetSelectedMessage()
{
Application outlook = new Application();
OlSelectionLocation select = outlook.ActiveExplorer().Selection.Location;
string selection = outlook.ActiveExplorer().Selection[1].EntryID;
return selection;
}
}
}
If I set the dropdown menu on top and set it to TESTOutlookInterop and hit 'Start' this works fine (when I call GetSelectedMessage() from TESTOutlookInterop's Main method it returns the string I'm looking for, in other words). For some context, this basically looks at the current Outlook process and returns the ID of whatever message is currently highlighted.
Now I've got a second project in this solution called TESTcore. I try to call the GetSelectedMessage() method like this:
using TESTOutlookInterop;
namespace TESTCore
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
OutlookInterop outlookinterop = new OutlookInterop();
ResultLabel.Content = outlookinterop.GetSelectedMessage();
}
}
}
If I set the dropdown in VS to run 'TESTcore' and run the Core app the 'GetSelectedMessage()' method gets called it behaves the same way it does when I try to run it in .NET Core (doesn't work at all, seemingly because the interop library is not compatible with Core). So how I do I call this interop method in the .NET Framework project from the Core project correctly?