An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Exception from HRESULT: 0x80070005 (E_ACCESSDENIED) - Error : 80070005 Access is denied.

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code

Additional information: 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)).

This Issue Is Occurring
When I tried to download excel file on cloud server! I debugging this code on the cloud server and find out, error is occurring at the time of creation of Microsoft.Office.Interop.Excel.Application object i.e.

using Excel = Microsoft.Office.Interop.Excel;
Excel.Application excel = new Excel.Application();

This is a COM permissions problem! I used forms authentication!

Firstly search Desktop folder in the below path – CREATE Desktop folder, if not exist!

For 64-bit (x64) - create this folder: C:\Windows\SysWOW64\config\systemprofile\Desktop
For 32-bit (x86) - create this folder: C:\Windows\System32\config\systemprofile\Desktop

Otherwise try to resolve below follow these steps - It might help you!
Solutions –
1.     Start => Run => dcomcnfg
2.     Open to Component Services => Component Services => Computers => My Computer => DCOM Config
3.     Find “Microsoft Excel Application”
4.     Right click => Properties
5.     Go to “Security Tab” and Edit the “Customize” radio buttons so that <Machine_name >/IIS_IUSRS could have rights for launch and access.
6.     Go to “Identity Tab” and choose “The interactive user”
7.     Apply changes and try again
References –

I hope you are enjoying with this post! Please share with you friends. Thank you!!

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog -
My Books - Book 1 and Book 2 Powered by Blogger.