Excel interop not working on user logout - c#

I have a weird problem, i have an silverlight application which uses Interop to execute a piece of code .
My Production server has a complex login procedure and the password never stays the same for a user after a stipulated time. i.e the password keeps changing.
So when i run this application , until any user is logged in the application works well, as soon as the person logs out or the session expires , the interop stops working as it doesn't have an interactive user.
I have read in several posts of this issue and majority like this asks to configure identity in the DCOMCNFG settings. But i am unable to find any microsoft office component (powerpoint,onenote,word,excel...) in my DCOMCNFG but in my local i am able to find it. Also the Interop is not found. The error is referring to this CLSID {00024500-0000-0000-C000-000000000046} .
How can i solve this issues. Is there any problem with the Office installation so as the file should appear in my DCOMCNFG ?
even if it does appear is there a ray of hope through which i can solve the identity problem ? as the password of my production server keeps changing so even if i go to the dcom component and go to identities tab in the properties , will i be able to give "this user" a fixed name and password ? or should i use the launching or interactive user ?
any help would be appreciated.

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.
You can read more about that in the Considerations for server-side Automation of Office article.

Related

Interacting with Outlook from an ASP.Net Core Blazor Web-site

I am converting an old Silverlight application into Asp.Net Core, using Blazor and Razor Pages.
The old application is opening Outlook, and creating an email ready to send with a Subject, From etc, plus a series of attachments. It is creating an object to do this using the following code:
Dynamic outlook = AutomationFactory.GetObject(“Outlook.Application”).
In my web-site, I do something similar:
Use a COM reference to the Microsoft Outlook 16.0 object library.
If Outlook is already running, then get a reference to its associated “Outlook.Application” COM object as per https://renenyffenegger.ch/notes/Microsoft/dot-net/namespaces-classes/System/Runtime/InteropServices/Marshal/GetActiveObject.
Otherwise, create an object using Microsoft.Office.Interop.Outlook.Application appOutlook = new Microsoft.Office.Interop.Outlook.Application();
This works when running my web-site locally in Visual Studio, however I cannot deploy it to Azure:
C:\Program Files\dotnet\sdk\6.0.201\Microsoft.Common.CurrentVersion.targets(2926,5): Error : MSB4803: The task "ResolveComReference" is not supported on the .NET Core version of MSBuild. Please use the .NET Framework version of MSBuild. See https://aka.ms/msbuild/MSB4803 for further details.
I’m assuming that I won’t be able to use this approach, however I can’t see any alternative. Any suggestions as to how I can do this in an ASP.Net Core Blazor web-site would be greatly appreciated.
You cannot use Outlook, or any other Office app, in a service (such as IIS). Even if you do manage to make it run, it won't help you - your code is running on the server, and the message you populate and display will be on the server, where nobody would ever see it.
You can either use a mailto: link (it supports address, subject, and body) or (if you need HTML and/or attachments), dynamically create an EML (MIME) file - Outlook on the client side will be happy to open it. To make sure the message is editable, add X-Unsent: 1 MIME header.
In my web-site, I do something similar:
Use a COM reference to the Microsoft Outlook 16.0 object library.
The Considerations for server-side Automation of Office states the following:
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.
From a JS code you can automate Outlook from Internet Explorer (only on Windows). Other browsers don't know anything about the COM technology. So, I'd suggest considering other approaches for getting the work done. The easiest way, like Dmitry suggested, is to use the mailto protocol. It opens a client's e-mail system and begins a new email message. The following example shows a link that will prepare an e-mail message:
<a href="mailto:user#example.com?
subject=MessageTitle&
body=Message Content">
Contact Us</a>
You may consider using EWS or Graph API if you need to send email silently.

NetOffice getting 80080005 Server execution failed

I'm trying to edit a Word document programmatically. However, when I debug and first try to create the Word.Application, I get
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
I see that Word.Interop isn't supported anymore, so I started using NetOffice, but nothing changed, so perhaps I'm not altering the underlying functionality.
I have tried many DCOM configurations and am running my Visual Studio instance as Administrator, but nothing changes. Currently Authentication Level is None, I specify "This user" and am using an account with all the Security permissions. I've also tried the interactive user and the launching user previously. I've never had trouble with the debugger before, just once it was deployed on the server, so this is confusing to me.
I'm running Windows 8.1 (64-bit) and Office 2013 (32-bit). I'd appreciate any ideas. And does NetOffice matter at all for this problem? Thank you.
See You may receive an "Error code 80080005 -- server execution failed." error message when you start many COM+ applications.
Anyway, 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.
Consider using Open XML SDK if you deal with open XML documents only, see Welcome to the Open XML SDK 2.5 for Office for more information. Or just try to use any third-party components components designed for the server-side execution.
P.S. NetOffice will not help you to avoid such issues because it is based on the COM Automation technology.

Connect ASP.net web site with outlook calendar

I have made one web site for configuring time slot for particular date. For example I stored Email id of user, date, Stating time of lecture, Ending time of lecture in database.
I want to display pop up on desktop before 5 minute of starting time.
Suppose I connect my database with outlook calendar.
How can I connect with outlook?
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 Exchange profiles only consider using EWS, see EWS Managed API, EWS, and web services in Exchange for more information. Or just use the System.Net namespace classes for accessing your mailbox.

Error with Excel and C# when logged off the server

I have written a Windows Service in C#. My service is meant to open an Excel macro-enabled workbook (this is in Excel 2010). I have installed this service on our server which is running Windows Server 2008 64-bit. My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this?
I get the following error:
System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a.
Excel is installed on the server, the service works fine when I am logged on the server but once all users have logged off, I get the above error. I would like the service to launch my Excel workbook regardless of an open session on the server or not.
My service seems to have a problem launching Excel when no one is logged on the server, does anyone have a solution to this.
Of course it has a problem. Windows Services cannot show a user interface, so how would you expect it to launch a GUI application like Microsoft Excel when there is no user logged in?
The specific COM error code that you receive means:
8000401a: The server process could not be started because the configured identity is incorrect. Check the username and password.
In other words, Excel is trying to start as an interactive user, which refers to the user that is currently logged on directly to the server console. Since no user is logged on, no interactive user exists, and the application fails when it tries to assume this identity.
The design was broken anyway: Excel was not designed to be run from a Windows Service. Create a standard Windows application instead. If you need it to run in the background without a UI of its own, don't create a window.
Basically, Cody Gray's answer is right. In the past I had a need to launch Excel from a Windows Service in order to print the file.
We were able to get past that kind of errors by setting the service to run as a specific user account and from time to time, log on as that user account and try to launch the files that failed to see the error messages popped up by Excel.
In your case, it is possibly because Excel is started for the first time and it asks you for something like your initials.
Are you using Office Automation to start Excel? Sorry, but Office Automation is not supported in service processes. It is designed to work only in an interactive process.
If you're lucky, Using Office Automation from a service process won't work. If you're not lucky, it will appear to work, and you'll actually put your application into production. You'll then start finding random bugs which are very difficult to reproduce, and even more difficult to fix without breaking something else.
That will be due to the fact that the real bug is a design bug - you used Office Automation from a service process.
Take it from the Voice of Experience...

Why not running Microsoft.Office.Interop.Outlook in asp.net?

I wrote some code about sending mail, Task, Appoinment etc. For example you can add someone to your outlook contact list over asp.net page. Every thing is ok on my local machine. But if I publish my application to a server I can not add noone on my outlook. Please help me it is important.
This is generally not a good idea, as Microsoft themselves state:
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.
Read the article to find out which obstacles await you.
I think you need to create an outlook/mapi profile on the server for the user that is sending the email. nOte that since you're runnning on ASP.NET then the user sending the email will be the identity of the Application pool that the virtual directory of the web application is running in.
This is an old article about creating a profile with outlook installed.

Categories