COM class factory Error in Microsoft.Office.Interop [duplicate] - c#

I am trying to convert a .xls file to an .xlsx file on the server-side using Microsoft.Office.Interop.Excel.Workbook class as follows:
workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
and I get the following error:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)). : System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
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 CALLING_METHOD_IN_MY_LIBRARY_HERE...
The problem is that this error occurs only on the staging server; on my local machine it works fine.
Things that I have tried on the staging server:
**1) Run dcomcnfg open Component Services
2) Expand Component Services "->" Computer "->" My Computer "->" the DCOM configuration "
3) Find the "Microsoft Excel application."
4) Right to open the Properties dialog box
5) Clicked on the "Security" tab,
6) "Launch and Activation Permissions, configure permissions, have added permissions - Identity run under Adminstrator user (This User), Interactive User and Launching Users
7). Launch and activation permissions + Access Permissions + Configuration Permissions => added IIS_IUSRS + Network Service with Full Controll**
2.
Changed the build of the project that converts the .xls file from "Any CPU" to "x86" on my local machine and published this library on the server.
Did someone figured out how to fix this problem? I am struggling on fix this issue for 2 days now.

Using DCOMCNFG.exe. Open it and go to:
Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application.
Open the properties, select Identity tab and select the interactive user.

I found the solution elsewhere.
Doing the following did solve my problem:
Using DCOMCNFG.exe. Open it and go to: Component Services -> Computers -> My Computer -> DCOM Config -> Microsoft Excel Application. Open the properties, select Identity tab and select the interactive user.
BUT - the problem came back every few minutes !
After hours of trying to figure out the cause, I noticed my server had hundreds of opened WINWORD.EXE processes. This caused a memory issue which leaded to the exception from hresult 0x80080005 error.
Well, stupidly enough, I forgot to write the code to close the interop application. Once I fixed that, the error was gone.
doc.Close(false);
Marshal.ReleaseComObject(doc);
word.Quit();
Marshal.ReleaseComObject(word);

I found this article which talks more about this issue in depth If this helps,
error “80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))” could occur due to following reasons:
The machine has a high CPU load and the process takes a long time to
start and fails to execute the CoRegisterClassObjects() in less than
120 seconds.
The COM server doesn't register for the right class IDs.
The COM server is currently stopping and there is a race condition
between CoCreateInstance and the COM server stopping part.
There is a security problem in the way the COM server is started
(this page seems to suggest misspelled passwords or lacking the
"Login as Batch Job" privilege for "Run As.." COM servers, but
anyway I would suggest re-verifying this information for your
specific configuration)
https://blogs.msdn.microsoft.com/adioltean/2005/06/24/when-cocreateinstance-returns-0x80080005-co_e_server_exec_failure/

I fixed this issue with this solution:
right click on Component Services/Computers/DCOM Config/Microsoft Word97 - 2003 Document
properties/General Tab
set Authentication Level:None

TLDR; the fix for me is to disable AutoRecover from File -> Options -> Save,
then discard all autorecovered files. It would appear it's the volume of autorecover files which is the root cause.
Background
I cycle through a lot open / close /compute cycles. Periodically the C# app fails to open a workbook with the below error.
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
The app repeatedly throws this error and is stuck in this state until the AutoRecovered files are cleared from Excel.
Another symptom follows; when I try to open Excel app (as if to create a new workbook, not open an existing one), it takes a long time spinning cpu cycles. It opens eventually and there are tons of files listed in the Recovered files pane on the left.
I Close the pane using the button, all the files are then discarded. Re-opening Excel again after this procedure is near instant. The app runs fine again from hereon.

Same problem was solved for me by "allowing desktop interaction" for the service. (in tomcat6w config tool on Log On tab)

Start -> Run (Windows+R)
Type: dcomcnfg -32 (hit enter)
this should open Component Services
Expand Component Services, Computers, My Computer, DCOM Config
Scroll down to "Microsoft Excel Application"
Right Click, select properties, go to Security tab
Edit Access Permissions
Click Add
Type <Computer_Name>/IIS_IUSRS (or go to Locations, select computer name - if using domain, by default, it will search the domain and will not find IIS_IUSRS)
Make sure the check box for "Allow" is checked for "Local Access"
Click OK, Click OK again (no rebooting is necessary)
Windows Update will reset this ever single time

Try to add Thread.Sleep Method, such as Thread.Sleep(2000) for 2 seconds after workBook.open and workBook.SaveAs two methods. If your Excel file has a lot of formats, try to extend few more seconds.

Related

Unreal Engine build crashes at C# trying to open Recycle Bin file

This boggles my mind, to the point that I wonder if isn't an SDK problem.
I share an Unreal Engine (4.26) game with a (non-technical) colleague through Git. Today he received his first code files from me, and to compile it, I had him install the SDKs(windows, .Net, C++ gaming, Visual Studio) and call Generate Visual Studio Project Files. It all generated just fine.
EDIT:
Emptying the recycle bin somehow fixed it, but now the problem repeats itself:
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:\System Volume Information' is denied.
So this entirely seems like a permission level problem to me, but I asked him to enable developer mode, to uncheck every read-only on Epic Games and Unreal Engine, and to run it in administrator mode. Nothing works. I don't see how we can get any more permissions than this.
Former message:
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:$RECYCLE.BIN\S-1-5-18' is denied.
Full logfile(minus some cleanup on my part):
Log file open, 04/17/21 12:00:08
LogInit: LLM is enabled
LogInit: LLM CsvWriter: off TraceWriter: off
LogInit: Display: Running engine for game: Naptin
LogPlatformFile: Not using cached read wrapper
LogTaskGraph: Started task graph with 5 named threads and 35 total threads with 3 sets of task threads.
LogStats: Stats thread started at 5.907298
LogD3D11RHI: Loaded GFSDK_Aftermath_Lib.x64.dll
LogICUInternationalization: ICU TimeZone Detection - Raw Offset: -5:00, Platform Override: ''
LogPluginManager: Mounting plugin MeshPainting
.....lots of LogPluginManager......
LogPluginManager: Mounting plugin SteamVR
LogXGEController: Cleaning working directory: C:/Users/adpar/AppData/Local/Temp/UnrealXGEWorkingDir/
LogXGEController: Cannot use XGE Controller as Incredibuild is not installed on this machine.
LogInit: Warning: Incompatible or missing module: Naptin
Running D:/.........UNREALENGINEFOLDER/UE_4.26/Engine/Binaries/DotNET/UnrealBuildTool.exe Development Win64 -Project="D:/....UNREAL/Naptin/Naptin/Naptin.uproject" -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
Using 'git status' to determine working set for adaptive non-unity build (D:\....UNREAL\Naptin\Naptin).
Creating makefile for NaptinEditor(no existing makefile)
#progress push 5%
Parsing headers for NaptinEditor
Running UnrealHeaderTool "D:\....UNREAL\Naptin\Naptin\Naptin.uproject" "D:\....UNREAL\Naptin\Naptin\Intermediate\Build\Win64\NaptinEditor\Development\NaptinEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="C:\Users\adpar\AppData\Local\UnrealBuildTool\Log_UHT.txt" -installed
Reflection code generated for NaptinEditor in 23.9260389 seconds
#progress pop
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:\$RECYCLE.BIN\S-1-5-18' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.DirectoryInfo.EnumerateFiles()
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 487
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 495
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 495
at Tools.DotNETCommon.FileFilter.ApplyToDirectory(DirectoryReference DirectoryName, Boolean bIgnoreSymlinks) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 408
at Tools.DotNETCommon.FilePattern.CreateMapping(HashSet`1 Files, FilePattern& SourcePattern, FilePattern& TargetPattern) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FilePattern.cs:line 340
at UnrealBuildTool.UEBuildBinary.PrepareRuntimeDependencies(List`1 RuntimeDependencies, Dictionary`2 TargetFileToSourceFile, DirectoryReference ExeDir) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildBinary.cs:line 294
at UnrealBuildTool.UEBuildTarget.Build(BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, Boolean bIsAssemblingBuild, List`1 SpecificFilesToCompile) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 1786
at UnrealBuildTool.BuildMode.CreateMakefile(BuildConfiguration BuildConfiguration, TargetDescriptor TargetDescriptor, ISourceFileWorkingSet WorkingSet) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 615
at UnrealBuildTool.BuildMode.Build(List`1 TargetDescriptors, BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, BuildOptions Options, FileReference WriteOutdatedActionsFile, Boolean bSkipPreBuildTargets) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 257
at UnrealBuildTool.BuildMode.Execute(CommandLineArguments Arguments) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 226
at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 550
LogInit: Warning: Still incompatible or missing module: Naptin
LogCore: Engine exit requested (reason: EngineExit() was called)
LogExit: Preparing to exit.
LogExit: Exiting.
Log file closed, 04/17/21 12:02:43
We have tried a few things, like generating again, or copypasting all of our assets to a new project: if we copy the assets, all good, if we copy the code, the same crash.
This happens only on his machine, so I'm kind of at a loss for words. He did not delete any files, the only difference between his machine and mine is that his SDK is more up-to-date by a few weeks.
I'd really appreciate any clue regarding why this file comes up in the build or how to stop it from crashing. The C++ code doesn't seem to be the issue at all, and he can't start Unreal Engine anymore.

Failed to load native library grpc_csharp_ext.x86.dll while running Azure Function in Visual Studio

lately I have encountered a following problem. Azure Function that is run in Visual Studio always throws an exception:
System.IO.IOException HResult=0x80131620 Message=Error loading
native library
"C:\Users\\AppData\Local\AzureFunctionsTools\Releases\2.16.0\cli\grpc_csharp_ext.x86.dll"
Source=Grpc.Core StackTrace: at
Grpc.Core.Internal.UnmanagedLibrary..ctor(String[]
libraryPathAlternatives) at
Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary() at
Grpc.Core.Internal.NativeExtension.LoadNativeMethods() at
Grpc.Core.Internal.NativeExtension..ctor() at
Grpc.Core.Internal.NativeExtension.Get() at
Grpc.Core.GrpcEnvironment.GrpcNativeInit() at
Grpc.Core.GrpcEnvironment..ctor() at
Grpc.Core.GrpcEnvironment.AddRef() at
Grpc.Core.Server..ctor(IEnumerable`1 options) at
Microsoft.Azure.WebJobs.Script.Grpc.GrpcServer..ctor(FunctionRpcBase
serviceImpl) in
C:\azure-webjobs-sdk-script\src\WebJobs.Script.Grpc\Server\GrpcServer.cs:line
24
The file that is supposedly missing is at its place of course. I've tried to reinstall Azure Function Tools and Visual Studio and nothing helped. Any ideas?
Thanks in advance.
EDIT1:
The problem seems to be caused by non-english characters in the path to the library. I've just created another account without them and suddenly everything started to work.
from the point that the root cause of error is because of the non-english characters in the path to the library, you can consider to rename path of your user profile.
To do so, here is the steps
Log out and login with another Administrator user to your PC
open command prompt by CTRL + R then type cmd
type wmic useraccount get name, sid and get SID of your profile
type regedit under start menu, right click on it and select Run as Administrator
Go under Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\YOUR_SID_HERE
Double Click on ProfileImagePath and change the value data according to your need (you can close Registry Editor)
go under USER PROFILES folder (%USERPROFILE%\..\) and change the path of your user profile accordingly
Restart your computer

Code runs on development server but not on IIS

I have a web application where user run queries(through web interface) and gets output in excel format. Sometimes this output comprises of more than 300k records. The user needs this data for further research.
Now in order to speed up the dynamic excel creation with such large volume of data, we are using "Microsoft.Office.Interop.Excel" COM object.
Our code works completely fine on the in-built asp.net development server. However, when hosted on the IIS, it gives us "Access is Denied" error (exact error is as shown below).
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I have given all the rights to the IIS user but still this is not working.
I have tried Windows Server 2012 R2 as well as Windows 7 OS and it doesn't work on both of them.
I have made changes to the "DCOMCNFG" and granted access to the web users under the "COM Security" tab also.
What are some additional steps I can take to make this work?
Have a look at the following links -
"Retrieving the COM class factory for component.... error: 80070005 Access is denied." (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
http://forums.iis.net/t/1205506.aspx?Retrieving+the+COM+class+factory+for+component+with+CLSID+failed+due+to+the+following+error+80070005+access+is+denied
https://waheedrous.wordpress.com/2014/01/26/error-office-interop-assemblies/
This is a COM permissions problem.
Start > Run > dcomcnfg
Navigate to Component Services > Computers > My Computer > DCOM Config
Locate the Microsoft Excel Application
Right click > Properties
On the security tab: Select Security under Launch and Activation Permissions and click Edit…
Add the account under which the site is running (eg: Network Service) and assign Local Launch & Local Activation permissions
Source
Also the ASP.NET Authentication should be enabled.
I think for this to work, office has to be installed on the server.
So if this is not the case, install Office on the server.
(alternative is to use OpenXml http://www.microsoft.com/en-us/download/details.aspx?id=30425)
I have decided to give up on using COM object for Excel operation on the server. Instead, I have decided to use EPPlus open office XML SDK for generation of Excel files. This works without any additional security permission requirement on the server.

ALM C# application

I am using Interop.TDAPIOLELib dll to connect to ALM (application lifecycle managment).
In order to connect to the project i am using TDConnection but when executing this line
_connection = new TDAPIOLELib.TDConnection();
i get this exception
Retrieving the COM class factory for component with CLSID {C5CBD7B2-490C-45F5-8C40-B8C3D108E6D7} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
This code was working fine before i repaired my HD
I run sfc/scannow and i got this message Windows Resource Protection did not find any integrity violations. Which indicate that i do not have any missing or corrupted system files.
any suggestions?
OTAClient.dll should be registered
using regsvr32.exe register the OTAClient.dll it located in this path C:\Program Files (x86)\Common Files\Mercury Interactive\TDAPIClient and make sure that the application is run under x86 target.
It's necesary to download the TDConnect.exe
Go to your HP ALM web interface
'Tool' link
'HP ALM Connectivity' link
Click on 'Download HP ALM Connectivity'
it will download TDConnect.exe file, you need to do this trhu your instance to match the TDConnect.exe with your version, for example if you are running HP ALM 11.52 you MUST download the TDConnect.exe for this version.
although this is an old question, but sharing what worked for me - the solution mentioned here - http://www.juvander.fi/site/Forums/tabid/129/forumid/2/threadid/14/scope/posts/Default.aspx
may help someone if nothing else works

Oracle oci.dll missing when running on MSTest agent

I'm trying to get some database related integration tests running on a MSTest test agent. We use c# and an oracle db with devart dotconnect.
Since we need to use indirect mode, I installed devart and an oracle client on the test agent.
The tests run smoothly when I execute them on my local machine. But when executed on the test agent (remotely), it can't find the client's oci.dll, which is a dependency somewhere:
System.IO.FileNotFoundException: Can not load Oracle client library oci.dll from home ..
Now, I have no idea why that happens. I checked the PATH environment variables already, but they seem fine. Any ideas why this works on my machine, but not when deployed to the test agent?
edit: added stacktrace within devart:
Devart.Data.Oracle.OracleHome.get_ClientVersion()
Devart.Data.Oracle.aw.a(Boolean A_0, Boolean A_1, OracleHome A_2, Boolean A_3)
Devart.Data.Oracle.OracleInternalConnection..ctor(aa connectionOptions, OracleInternalConnection proxyConnection)
Devart.Data.Oracle.cs.a(k A_0, Object A_1, DbConnectionBase A_2)
Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, k A_1, DbConnectionBase A_2)
Devart.Common.DbConnectionPool.a(DbConnectionBase A_0)
Devart.Common.DbConnectionPool.GetObject(DbConnectionBase owningConnection)
Devart.Common.DbConnectionFactory.a(DbConnectionBase A_0)
Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
Devart.Common.DbConnectionBase.Open()
Devart.Data.Oracle.OracleConnection.Open()
Thanks for the replies, got the right pointers. Apparently the problem occurs when a 64bit thread tries to load a 32bit OCI.DLL and vice versa. However, I played around with the test settings and build settings related to 32/64 things, but to no avail.
Anyway, I was able to solve the problem by additionally installing a 64-bit Oracle Client on the test agent. For some reason it seems that then the QTAgent thread finds the right OCI.DLL.
Faced the same problem in a console project. I fixed it by changing the compilation platform setting by going to
project properties -> Compilation -> Destination of the platform and selecting x86.

Categories