Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COMException CreateInstance failed on publish

I'm currently developing a C# WebAPI project that references a third-party api dll. The component is a simple COM reference that I added to the visual studio project.
The web API is published on an intranet server (IIS) with integrated security & user impersonation turned on, anonymous auth turned off.

When running the web api in visual studio (2015) on my local machine, everything works perfectly.

When running the published web api on our IIS server, everything also works fine, however when I send a request to a controller action that uses the third party library, I receive following error:

System.Runtime.InteropServices.COMException
Additional information:
CreateInstance failed.
at ThirdPartyLib.Connect()

The third party dependency was installed on the server (as well as my dev machine) using their installer. This registered a set of dll's and installed accompanying software. I have verified correct installation. In fact, a simple winforms application using the same dll works just fine.

Process Monitor shows w3wp.exe is using the correct dll.

I'm not sure what I'm missing?
If this is a rights problem, how would I go about solving it?

like image 531
Bart Avatar asked Nov 10 '16 16:11

Bart


1 Answers

You can change Application Pool Identity to a user with higher permissions.

Note: You can use ASP.NET Impersonation using web config to run the whole application with a specific identity or using code to run just a part of code using a specific identity. For example I tested <identity impersonate="true" userName="r.aghaei" password="mypassword"/> for a file system permission and it worked properly. Just pay attention impersonation in webconfig or in code, just works if application pool user have sufficient rights to allow impersonation. For more information about how to use impersonation inn config or code see this MSDN KB article.

Also don't neglect least privilege principal.

like image 103
Reza Aghaei Avatar answered Sep 29 '22 23:09

Reza Aghaei