NetOfficeFw / NetOffice

🌌 Create add-ins and automation code for Microsoft Office applications.
MIT License
697 stars 143 forks source link

"Unable to create instance of <Outlook.Application> initialising an Outlook.Application #334

Closed kev160967 closed 4 months ago

kev160967 commented 2 years ago

We're having an issue with latest version of the outlook integration. Our use case is that we create an outlook message body, with default sender and recipient in our application, then call Display on the message to open the outlook compose window. Our issue occurs before any of this though, when we call the Outlook.Application constructor. Our application is running in a citrix desktop session, and is a streamed AppV package. Office 365 is an installed application in the desktop session.

We get the following error when we invoke the constructor:

`Outer Exception: COMException Unable to create instance of: This is typically because you have no access to the desktop subsystem from a Windows Service/IIS module in default configuration because it is running in a restricted context/principal. at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject)
at NetOffice.OutlookApi.Application..ctor(Boolean enableProxyService)

Inner Exception: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 8000ffff Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).

at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject)`

kev160967 commented 2 years ago

Prior to this release, this was working correctly in this environment, and still works when we rolled back to the previously working version. Initially I tested this in the citrix desktop session, but was unable to reproduce it - the outlook compose window opened correctly for me. I was able to reproduce the error this morning though. I don't use citrix day to day, so my outlook profile hadn't been configured, and didn't have my email account attached to it. This meant I could compose an email but not send it. This morning I added my email account (an exchange server account) and now I can reproduce the problem. I'm not sure if that might provide any clues as to what the issue might be

kev160967 commented 2 years ago

At the moment my suspicion is that this is a clash with another package, but I'm not sure how to isolate it any further. I'd welcome any suggestions for debugging this further

jozefizso commented 2 years ago

Please, configure your system correctly:

This is typically because you have no access to the desktop subsystem from a Windows Service/IIS module in default configuration because it is running in a restricted context/principal.

kev160967 commented 2 years ago

@jozefizso I'm sorry to bang on about this, but if that was the problem then why would it work with previous versions of the package? What would you suggest doing to our system in order to configure it?

jozefizso commented 2 years ago

I don't know the configuration of your system.

You are free to use the old library or use COM directly.

For support question and configuration issues it is better to ask on StackOverflow or to contact Microsoft Support.

kev160967 commented 2 years ago

Thank you, looks like using the old library may be the solution, as it appears that our system is correctly configured to work with that version.

koffeinfrei commented 7 months ago

We're experiencing the same error on the call var outlook = new Application():

Unable to create instance of:<Outlook.Application>
This is typically because you have no access to the desktop subsystem from a Windows Service/IIS module in default configuration because it is running in a restricted context/principal.
   at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject)
   at NetOffice.OutlookApi.Application..ctor(Boolean enableProxyService)
   at NetOffice.OutlookApi.Application..ctor()
   at Bridge.Action.Outlook.Execute(IModel channel, BasicDeliverEventArgs eventArgs) in 
   [...]

With classic Outlook everything works. When enabling the new office the above error occurrs.

While it has been mentioned to configure the system properly I can't seem to figure out what the configuration issue with this could be. I tried with an elevated account (admin) too. There seems to be something about the new outlook's compatibility. If you have any suggestions on how to further debug this I'd be happy to dig a bit more.

jozefizso commented 7 months ago

@koffeinfrei unless you provide all the information about your app, system, configuration, permissions and a reproducible sample, no one can tell what is configured incorrectly.

koffeinfrei commented 7 months ago

unless you provide all the information about your app, system, configuration, permissions and a reproducible sample,

Before I provide all the information (which sounds like a lot) I wanted to get some suggestions and pointers on how to proceed and try to narrow down the issue a bit further.

Is this library generally working with the new outlook? I'm not even sure if it's supposed to work, or if I'm missing a configuration option or an additional library or something.

The error message "Windows Service/IIS module" also confuses me, since neither is true in our case.

Thanks for your help.

kev160967 commented 7 months ago

@koffeinfrei In case it helps, we are using NetOfficeFW instead and are having no issues with the latest version of Outlook. I was able to resolve my problem at the start of this thread simply by switching to that package. It seemed like there was some falling out between the owners of NetOffice that led to the split between NetOffice and NetOfficeFW, but who has time to care about such internal politics?

koffeinfrei commented 7 months ago

@kev160967 Thanks, but this is the NetOfficeFW repo :sweat_smile:, and we are using this one. The previous https://github.com/netoffice/NetOffice looks abandoned (hasn't been updated since 2020). Unless you mean something different?

kev160967 commented 7 months ago

Whoops, yes, my bad! Looks like I was getting mixed up with this issue and a previous one. I think in this case we reverted to an older version of the package - we have version 1.9.0 locked in the project file, and it looks like that's what my comment about "using the old library" referred to. Yours might be a different problem though, as we encountered this before New Outlook was a thing. Your symptoms seem the same though, and its an easy thing to change and check. Good luck!

sg2707 commented 1 month ago

We're experiencing the same error on the call var outlook = new Application():

Unable to create instance of:<Outlook.Application>
This is typically because you have no access to the desktop subsystem from a Windows Service/IIS module in default configuration because it is running in a restricted context/principal.
   at NetOffice.COMObject.CreateFromProgId(String progId, Boolean factoryAddObject)
   at NetOffice.OutlookApi.Application..ctor(Boolean enableProxyService)
   at NetOffice.OutlookApi.Application..ctor()
   at Bridge.Action.Outlook.Execute(IModel channel, BasicDeliverEventArgs eventArgs) in 
   [...]

With classic Outlook everything works. When enabling the new office the above error occurrs.

  • .NET 7.0 WPF
  • NetOffice 1.9.5
  • Classic Outlook: 365 MSO (Version 2402 Build 16.0.17328.20124)
  • New Outlook: 1.2024.306.400

While it has been mentioned to configure the system properly I can't seem to figure out what the configuration issue with this could be. I tried with an elevated account (admin) too. There seems to be something about the new outlook's compatibility. If you have any suggestions on how to further debug this I'd be happy to dig a bit more.

@koffeinfrei Did you get any solution for this issue? reverting to 1.9.0 is also not working. (with the new outlook)

jozefizso commented 1 month ago

NetOffice does not support "new Outlook". That is just a wrapper around a web page.