Initializing an external COM object causes w3wp.exe to crash with "Access Violation" error

0

I'm trying to implement Brother b-Pac printing library for label printing devices into my web application. I need to create/load the label template on server and print from the client's machine over a browser.

My code is totally working on my development environment. It only occurs on the published version. It's an access denied error thrown when the COM object got called by the app. I suspect there's an inner exception I couldn't reach.

The event got logged as follows:

Faulting application name: w3wp.exe, version: 8.5.9600.16384
Faulting module name: bpac.dll, version: 3.2.0.20
Exception code: 0xc0000005
Fault offset: 0x0010beea
Faulting application path: C:\Windows\SysWOW64\inetsrv\w3wp.exe
Faulting module path: C:\Program Files (x86)\Common Files\Brother\b-PAC\bpac.dll

I also used DebugDiag on the dump file and here's the report. Though it says here debugger couldn't locate debug symbols for bpac.dll, so it may be incomplete (If it may help, I'd like to know where and how to get symbols for a 3rd party DLL)

Application is a multilayer ASP.NET MVC app targeting the .NET Framework 4.6.1, running on a virtual machine with Windows Server 2012 R2 (x64) and IIS 8. (If it matters the project is derived from this template)

I searched about the issue and tried the following solutions:

  • Give read/write permissions of wwwroot and DLL's own folder to the IIS APPPOOL/user of the faulting w3wp.exe.
  • Give same permissions to IIS_IUSRS, NETWORK, NETWORK SERVICE users.
  • Impersonate Administrator user.
  • Uninstall/install 32bit/64bit versions of the b-Pac SDK.
  • Change bitness of my ASP app and all projects within to x86/x64.
  • Enable 32bit on the Application Pool.
  • Patch the Windows for July 2018 update issue
  • Setting Anonymous Authentication, App pool identity etc. all to the default pool user.
  • Loading the DLL dynamically. (not sure if I did this correctly though)

The COM object I'm trying to initialize is bpac.Document. Interface is IDocument and the concrete class is DocumentClass. I wasn't familiar with any of these concepts before. And I'm still struggling to understand but I tried all of these following lines for initialization:

Document label = new Document();
DocumentClass label = new DocumentClass(); //embed interop types: false
IDocument label = new Document();

After that, I'm using label object to open a template and etc. But as soon as the application hits any of the above lines it crashes the server and restarts the app.

Incidentally, the DLL file is referenced as a COM library in my WebService (App) project (not in the Web project). So it doesn't get copied on bin folder (I guess that's the correct behaviour?). Tried changing isolation/interop settings but I'm not sure if those are related to the issue at hand.

I read things about Registering COM objects into GAC and Marshalling for Remote Access but I couldn't grasp how to apply these properly. Thing is, the official documentation doesn't say anything about this. And there isn't a single example for using b-Pac library on a modern C# ASP.NET setting (only a little on VB ~eww~).

I'm a developer, not a DBA so I'm not too confident with tweaking the server's settings. But for this issue alone, I modified too many things too many times.

c#
asp.net
iis
com
w3wp
asked on Stack Overflow Feb 5, 2019 by Emre Can Serteli • edited Feb 8, 2019 by halfer

1 Answer

0

So, the problem was about the app id permissions all along. I changed the Application Pool's identity to LocalSystem and now it works as expected.

Still, I'm not sure what kind of security flaws this change would cause in the future. I posted this link to the vendor's technical staff. But they didn't give me an answer yet.

answered on Stack Overflow Feb 12, 2019 by Emre Can Serteli

User contributions licensed under CC BY-SA 3.0