Search code examples
c#outlookoutlook-addinoffice-interopoffice-addins

How to integrate Outlook C# class library in ASP.NET MVC on .NET Framework v4.8


I have created a web addin for the outlook. I have configured an ASP.NET MVC project in the manifest file.

The page was rendering on the click of add-in button I have created.

  • But when I have modified the action method as below, It's not working. I have added breakpoint to check if objOutlookApplication is filled or not.
  • But when breakpoint hit on that line and giving F10, Execution/Breakpoint is not going to the next line & ASP.NET MVC application is loading continuously.
  • I have added a breakpoint in the catch block also to see if any exception occurred. But no exception occurred there.

This is my code.

public ActionResult Index()
{
    try
    {
        OutLook.Application objOutlookApplication = new OutLook.Application();
        OutLook.Inspector objOutlookInspector = objOutlookApplication.ActiveInspector();
        OutLook.Explorer objOutlookExplorer = objOutlookApplication.ActiveExplorer();
    }
    catch(System.Exception e)
    {
    }
    return View();
}

I have only installed Microsoft.Office.Interop.Outlook NuGet of v14.0.0.

Is there any mistake in configuration ? Please provide me solution for this.


Solution

  • I have created a web addin for the outlook. I have configured an ASP.NET MVC project in the manifest file.

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article.

    If you deal with Office365 accounts you may consider using Graph API from the server side. In case of Exchange on-premise consider using EWS, see Start using web services in Exchange for more information.