0

I am using a third party .net library, which loads a dll using

Kernel.LoadLibrary(DllFileName)

Everything works fine when this code executed in a c# console application, but when im trying to use the library from a web app (an mvc app), im getting an "Invalid access to memory location" exception. Do i have to change some settings in order to load a managed dll from an web app?

let me know if any other details is needed

Joe
  • 255
  • 2
  • 6
  • 21

1 Answers1

0

It might be a bit-ness problem. Kernel.LoadLibrary is probably a PInvoke call to the unmanaged LoadLibrary call, likely used to load an unmanaged library. If it doesn't check whether the process is 32-bit or 64-bit and load the appropriate version of the unmanged library, you'll have issues (I actually thought you'd get an error about an invalid format, but the different message may be because it's skipping some of the other protections). Try forcing 32-bit mode and see if it helps (or changes the error): IIS 6 or IIS 7.

Though the error message doesn't seem to match what I'd expect for a 'file not found' problem, another difference between a console application and web application that could matter is that the current directory is different (in case the third-party library doesn't pass a full path to LoadLIbrary) - it is usually the directory of the application when running a console app, but it usually starts out as a windows system directory in a webapp. This could matter if it's expecting the DLL it's loading to be in the current directory. If you suspect it's loading the wrong file, Process Monitor can be a very useful tool - it'll let you see all the activity the process is doing, such as what files it tries to load and the like.

Jonathan Rupp
  • 15,522
  • 5
  • 45
  • 61
  • You are right, its a pInvoke call to a unmanaged LoadLibrary call. i Actually tried to changing the setting to support 32bit mode, and it still gives me the same error. InValid Access to memory location(error code 998). – Joe Jul 08 '12 at 14:28