[.net] DllImport on an embedded unmanaged DLL

Started by
2 comments, last by bgreen 17 years, 9 months ago
Hi, I have an unmanaged dll that I need to call into, and I'd like to try and embed the unmanaged dll within my class library's assembly, so that I only have to worry about 1 file instead of 2. I've written the managed wrapper around the dll, and everything works 100% as long as the DLL is in the bin directory with the assembly. It's when I try embed it that I run into problems. I've followed the instructions at this blog post to no avail: http://blogs.msdn.com/suzcook/archive/2004/10/28/249280.aspx. The error I get is "MyMethod' failed: System.UnauthorizedAccessException : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))". I've tried a number of things, but I'm really no closer to figuring out why I'm getting E_ACCESSDENIED. I thought first that it was because I was trying to extract the resource from the same assembly as my DllImport, but moving the embedded dll to a new assembly didn't fix the problem. I've also tried providing a strong name keyfile for the assembly, to no avail. Incidentally, I get the error whether the name of my embedded dll is spelled correctly in the DllImport or not, so I assume it's not even trying to extract the resource from the dll yet. Does anybody have any ideas? PS. .NET 2.0, running from Visual Studio 2005 Professional.
We scratch our eternal itchA twentieth century bitchWe are grateful forOur Iron Lung
Advertisement
I don't think you can DllImport an embedded DLL; under the hood I'm sure there's a GetProcAddress call somewhere, which requires a standalone DLL file. The article you refer to discusses adding an unmanaged DLL to an assembly, but keep in mind that assemblies can consist of multiple files.

Perhaps then it's worth my while to write code to extract the embedded dll at runtime, and then delete it when I'm finished. Then I only have to manage one file. I wonder if it's worth the effort...
We scratch our eternal itchA twentieth century bitchWe are grateful forOur Iron Lung
I think you'd be far better off spending some time on the deployment of your app.

This topic is closed to new replies.

Advertisement