I try convert Office documents using Office.Interop running under separate Windows service.
This service is running under specific account (username in future).
All folder access rights is set for this account. And when i try to create any of Office application (for example, var app=new Excel.Application()) then my code fails with exception:
Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: E_ACCESSDENIED.
Ok, but i have already configured the DCOM permissions for this CLSID! I open the dcomcnfg.exe , select component with this CLSID, opening settings, security and see that user of this service have all rights for this component.
Why this exception throws?
Ocka guys, i found the answer.
1) Be sure that you have install a right version of Office 2007
2) Be sure that you have install a PDF\XPS addin
3) Just office and its addin installed, you should run DCOMCNFG and pick My Computer->DCOM config. As it turned out, after office installation there is no mappings between CLSID and AppID in registry.
4) Close dcomcnfg window. Now there is right mappings in registry. You should get all things related to office (its id, e.g. {XXXXXXX-XXXX...}) in HKCR\AppID and HKCR\CLSID
5) For all these id's you should grant access, this can be achieved using this algorythm:
* open HKCR\AppID{id} key
* setup LaunchPermission and ActivatePermission values (code to do this find there in stackoverflow)
* Set value "RunAs" as "Interactive User"
Ocka, your office automation should work correctly, if i didn't forget some step..
Related
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.
When I try to access an Excel spreadsheet using the following code I get a "Library not registered' error when defining the workbook object wrkbuk using C# from Visual Studio 2012 with Office 2007 (ver 12) installed
Microsoft.Office.Interop.Excel.Application excapp = new Microsoft.Office.Interop.Excel.Application();
string bookname = #"C:\Users\Public\Documents\RECRUITMENT & SELECTION\MOVEMENTS\MOVEMENTS\Miscellaneous Documents\VacanciesREAL.xls";
Workbook wrkbuk = excapp.Workbooks.Open(bookname);
Worksheet wrksht = new Worksheet();
The error details are
System.InvalidCastException was unhandled HResult=-2147467262
Message=Unable to cast COM object of type
'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type
'Microsoft.Office.Interop.Excel._Application'. This operation failed
because the QueryInterface call on the COM component for the interface
with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the
following error: Library not registered. (Exception from HRESULT:
0x8002801D (TYPE_E_LIBNOTREGISTERED)). Source=mscorlib
I've created a reference to Microsoft.Office.Interop.Excel.dll in the Office 14 Primary Interop Assembly that comes with VS 2012 and also for the Office 12 version of the dll and neither fixes the problem. I've tried registering the dlls with regasm but this does not help either.
I can create the worksheet wrksht on the following line OK with the Office 14 and Office 12 dlls so the problem seems only affect workbook definition.
Dec 17 2013
Tried reinstalling Office 2007 to no avail but found this solution, which worked. It was at
http://social.msdn.microsoft.com/Forums/vstudio/en-US/d3f92da7-96d3-404b-89d0-d236800ceae5/vs-2012-rc-and-visual-studio-tools-for-office?forum=vsto
Problem is code from multiple versions of Office - I had code from Office 14, possibly coming from VS 2012 install
I suspect that VS 2012 RC has installed the Office 2013 type libraries, and that there are now duplicate versions registered. I got that specific error message
('unable to cast
_Application'....'TYPE_E_LIBNOTREGISTERED')
after a messy uninstall, and then re-installing an older version of Office. I solved it by following the advice of another forum thread here which I'm sadly unable to find...basically I searched the registry for the CLSID in the error message, so, {00020970-0000-0000-C000-000000000046}. Its registry key contained two keys, one of which was called 'TypeLib', which in turn contained another CLSID for the type library. I then searched the registry, starting at the beginning again, for that second CLSID, which led me to the relevant interop type library. It had two entries....8.3 and 8.4, the bigger number corresponding to the later version of Office....which I deleted...and immediately was able to run my program.
I had this exact same problem. Here's how I fixed it:
Go to
HKEY_CLASSES_ROOT\TypeLib\ and search for Office.Interop.Excel.
I found HKEY_CLASSES_ROOT\TypeLib\(guid)\1.8 but its child nodes were empty! I deleted it because Office 15 wasn't installed on that machine, and hey presto - it worked.
Either our VSTO project installer, or our own custom installer must have placed the 1.8 folder there.
I found the solution here:
Error accessing COM components
I had exactly the same issue. If you have installed a new version of Office and for some reason you have to install the older version without removing the new one (For my case I just need to install the Office XP Photo Editor) and this caused the issue.
After spending 3 hours up and down, the best way is to repair the new version of Office and everything was back to normal as it should be.
Hope this info helps provided you have the same or similar scenario.
Something which hasn't been mentioned here but which may be useful is that subkeys of 1.XX can cause issues as well. For example:
Under Computer\HKEY_CLASSES_ROOT\TypeLib{00020813-0000-0000-C000-000000000046} I had the subkey 1.9. This in turn has the subkey 0(or should). Now under this, there were two subkeys - Win32 and Win64. As a result, Visual Studio was unable to resolve the location of Microsoft.Office.Interop.Excel.dll - it was reading two subkeys where it could only read one. Deleting the Win32 subkey fixed my issue completely. Please note that this was done after a complete reinstall of VS 2017 & Office 365 Pro Plus. Hope this helps someone.
I will confirm #stuzor 's answer on two machines I've encountered.
Background:
Windows7 64 bit
Office 2010 (32bit)
Lync 2013
HKEY_CLASSES_ROOT\TypeLib\ , searched for "Office.Interop.Excel". Found the barely existent "1.8" folder. Upon deletion, the function in an old VB.net app began working immediately.
This is an answer if you can not modify or delete the regedit records. I had the same problem, in the company where I work, there are about 30 machines with office 2010 and I could not erase or open records in the regedit. because the client machine was in a domain that would not let me. although I had administrator permissions it did not allow me to delete records in the regedit. I tried to find a solution for 1 month, and I did not find it. so I had to stop using interop and migrate to OpenXml to edit excel templates and ClosedXml to create new excel. This saved my life, because my boss was already pressing me.
Open the project/solution in Visual Studio, and open the console using the Tools > NuGet Package Manager > Package Manager Console command.
and install 2 packages
Install-Package DocumentFormat.OpenXml -Version 2.5.0
Install-Package SpreadsheetLight
pd: OpenXml 2.8 dont work with SpreadsheetLight, better use 2.5.0
add this in the beggining
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using SpreadsheetLight;
in your button or class copy and modify
SaveFileDialog fichero = new SaveFileDialog();
fichero.Filter = "Excel (*.xlsx)|*.xlsx";
if (fichero.ShowDialog() == DialogResult.OK)
{
SLDocument sl = new SLDocument("c:\\bin\\est1.xlsx", "Sheet1");
sl.SetCellValue("E9", "Let's party!!!!111!!!1");
sl.SelectWorksheet("Sheet2");
sl.SetCellValue("C7", "Before anyone calls the popo!");
sl.AddWorksheet("ERTRT");
sl.SetCellValue("B4", "Who let the dogs out?");
sl.SetCellValue("B5", "Woof!");
sl.SaveAs(fichero.FileName);
MessageBox.Show("Report " + fichero.FileName + "!");
}
The registry hack described above fixed the same problem for me. The only difference was I had a 1.9
and a 1.7 entry. I deleted the 1.9 key and my problem was fixed.
Other info:
OS: Windows 10
Visual Studio Professional 2015
C# Windows Form Application
This was on my work laptop. We have Office 2010 installed on each workstation.
Some other things I tried that DID NOT WORK were the following:
Repairing MS OFFICE
Reinstalling MS OFFICE
Downloading Microsoft Office 2010: Primary Interop Assemblies from Microsoft.
I also had several versions of the Microsoft.Office.Interop.Excel.dll on my laptop. Deleting previous versions did not fix the problem.
Glad I went to STACKOVERFLOW.COM because this place ROCKS!!!!!!
We had the same problem.
Our setup is like this :
Office 2010 : Word and Excel
but
Office 2013 : Outlook
We ran the installation program for Office 2010 and choose the repair option.
After that, all the wrong keys in the registry for Word and Excel were deleted and the problem was solved.
Had the same problem... The code that was previously running, started throwing the same exception when a new Application instance was created. To fix this:
Programs and Features, did an order by date installed and could see there were some Microsoft Office 365 updates from the same day the
code had stopped working.
For both Microsoft Office 365 -en-us and Microsoft Office 365 Pro Plus -en-us, right click Change and select Quick Fix
Tried to run my solution and it was working again.
I try open .doc file with interop, when I debug code in Visual studio result is a file but I publish web to IIS result is null.
I'm using Windows server 2012 64bit and Microsoft Office 2007.
Why result in IIS return null and solution?
var wordApp = new Application { Visible = false };
var path = Request.PhysicalApplicationPath + "File\\TestFile.doc";
object srcPath = path;
var wordDoc = wordApp.Documents.Open(ref srcPath);
When you execute the program from the Visual studio then code uses the logged in user to make calls for COM components(Microsoft word). Generally logged in user has permission to execute the calls on the COM component. So code will work in the Visual studio.
When you publish the website into IIS then it uses default user of IIS to make the call to COM component. If that user doesn't have the permission then call fails and throws the exception.
First find out the user that IIS is using. Add that user to the specific COM component and give the permission to execute the calls.
Start > Run > dcomcnfg
Navigate to Component Services > Computers > My Computer > DCOM Config
Locate to "Microsoft Word 97 – 2003 Document" > Right click > Properties
On the security tab: Select all radio to (Use default)
i am trying to deploy an asp.net web service application to IIS 7.5. The application used .Net framework 3.5. dev machine is win 7 64bit. i have used following code snippet to create HTML and then convert it to pdf using Amyuni Document Converter 450.
private InternetExplorer internetExplorer = new InternetExplorerClass();
when i deploy the application in local development server it perfectly run but whn i deploy it using the local iis server it gives following error. any reasons for that.. i have used impersonate='true'
System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0002DF01-0000-0000-C000-000000000046} failed due to the following error: 80080005.
You have to change property in DComConfig for ie.
Follow the next steps:
Start->Run->dcomcnfg->Component services>Computers>My Computer
Right click on My Computer and select Properties. On the Security COM tab set the Default Autethentication level and Default Impersonation level.
I am a .Net developer. New to OPC. When I tried some samples of OPC Client all of them give this error. It seems the DLL is not registered it seems. But I don't know how and where to register this.
error: retrieving the COM class factory for component with CLSID failed due to the following error: 80040154
Even I tried this
regsvr32 Interop.OPCAutomation.dll",
but it also throws error like
The module "Interop.OPCAutomation.dll" was loaded but the entry-point DllRegisterServeer was not found.
Make sure that "Interop.OPCAutomation.dll" is a valid DLL or OCX file and then try again.
I have gone through so many existing forums. So many of them said to change the Platform Target to x86 and still I am having the same issue. FYI, I can see only see 'Active (Any CPU)' in the Platform option from the top of the Build tab of Project Properties.
Here are my environment details:
.Net 2005
OPCAutomation Weapper
Windows 7 64-bit OS
Dell Inspiron 1525 (I hope this is not a 64bit machine, but my engineer installed 64bit OS somehow).
Please help me.
Thanks in advance!
Just in case somebody is dealing with this problem (as I've recently been...) I get through it! After some time, I found out that it's something about the .NET framework running on 64-bit machines. As long as the.NET application works only with 32-bit CLR, we must set .NET framework to load CLR in WOW mode. To do so, type:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow
After this you should be able to run the applications.
You can go back and revert .NET Framework as it was before by typing:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64
If the OPC Client Toolkit SDK (C++) is used, a problem with the remote registry service may cause this error as well.
On Windows 7, by default the Remote Registry service is set to manual and not started. Ensure that the Remote Registry service is started on all of the machines you want to deploy to. This can be done manually or using Group Policy.
The function GetCLSIDFromRemoteRegistry() uses the RemoteRegistryService in order to get the CLSID of an OPC Server. If this service is not started on the client machine, the OPC program may return the error 80040154.
The error you're getting is more than likely due to the OPC server not being properly registered. Make sure it is registered (usually by running it at the command line with a "/regserver" or "/service" parameter). There may also be security issues in which case you'd have to run 'dcomcnfg' (DCOM Config) to make sure the client has access to the server.
This question is a bit dated so I hope you figured it out by now, but I had the same exact issue and wanted to share my solution. In my case, I am using a Kepware server. If you compile and try to run a client application for this server using Interop.OPCAutomation on a machine that does not have the server installed, you will get a dll not registered error and "entry point not found" if you try to register the dll manually.
Solution: Make sure you've got the server installed and running.
Although this is an old post, I would like to share my solution.
My problem was that when I tried to install an application with the OPCAutomation.dll, it gave me 80040154 error because the class was not registered.
This is my solution, always with Administrator privileges:
Copy OPCDAAuto.dll into the "C:\Windows\System32" folder
On the cmd prompt type "C:\Windows\System32\regsvr32 opcdaauto.dll"
You should watch a message like this one:
image
Hope this helps!
The OPC dll only works in 32 Bits, my solution was to change the "Enable 32-Bit Applications" to True in the advanced settings of the relative app pool in IIS.