.NET experts pls read

Author
Discussion

tim_s

Original Poster:

299 posts

261 months

Thursday 4th September 2003
quotequote all
i'm trying to import a dll written in VC++ 6 into my web application (C#). The dll uses dynamic linking and writes an mdb file using DAO.

The Problem:
When run from an EXE all is OK (C++ exe), when run from a web app the dll throws an exception and when the dll is debugged its says "DAO failed to initialize etc".

I'm importing the dll using [DllImport(@"c:winntsystem32mydll.dll")]

does anyone know how I can fix this?

plotloss

67,280 posts

277 months

Thursday 4th September 2003
quotequote all
Not some sort of authority issue is it?

wimdows

108 posts

259 months

Thursday 4th September 2003
quotequote all
tim_s said:
i'm trying to import a dll written in VC++ 6 into my web application (C#). The dll uses dynamic linking and writes an mdb file using DAO.

The Problem:
When run from an EXE all is OK (C++ exe), when run from a web app the dll throws an exception and when the dll is debugged its says "DAO failed to initialize etc".

I'm importing the dll using [DllImport(@"c:winntsystem32mydll.dll")]

does anyone know how I can fix this?


First up, you should include the namespace System.Runtime.InteropServices for your project, but you probably already have that in there.

Additionally, you might want to grant read access to that DLL for the ASPNET account.

And lastly, does your "mydll.dll" depend on other existing DLL's and are permissions set properly on these? Check with dependency walker (depends.exe) or similar tools.

Good luck.

Wim

tim_s

Original Poster:

299 posts

261 months

Friday 5th September 2003
quotequote all
hi,

yep i had included the interopservices namespace.

i too thought it could be permissions but after giving the ASPNET account full access to my hard drive i've decided it must be something else.

wimdows

108 posts

259 months

Friday 5th September 2003
quotequote all
tim_s said:
hi,

yep i had included the interopservices namespace.

i too thought it could be permissions but after giving the ASPNET account full access to my hard drive i've decided it must be something else.


Have you tried to run it from a Winforms or console app? It might not necessarily be file permissions but could be account policies.

wimdows

108 posts

259 months

Friday 5th September 2003
quotequote all
You also might want to add the SetLastError attribute, so:

[DllImport(@"c:winntsystem32mydll.dll"),SetLastError(true)]

After calling whatever method of your DLL, you can then retrieve the last Win32 error using:

System.Runtime.InteropServices.Marshal.GetLastWin32Error()

Not sure wheter that will give you more info, but it's worth a shot.

tim_s

Original Poster:

299 posts

261 months

Friday 5th September 2003
quotequote all
wimdows said:


tim_s said:
hi,

yep i had included the interopservices namespace.

i too thought it could be permissions but after giving the ASPNET account full access to my hard drive i've decided it must be something else.




Have you tried to run it from a Winforms or console app? It might not necessarily be file permissions but could be account policies.



hey thanks for the responses so far!

yeah i've tried running it from a windows app and it works!?! how can I change account policies for the ASPNET account?

>> Edited by tim_s on Friday 5th September 11:24

wimdows

108 posts

259 months

Friday 5th September 2003
quotequote all
You don't really want to change account policies for the ASPNET account, as this will effect all web apps.

Best thing is to use impersonation, and use the account that you are logged in as (since this doesn't seem to result in any conflict when running from a Winforms or Console app).

A search for "impersonation" and "ASP.NET" on Google will most certainly yield a good number of results.

Hope that helps.
Wim

Don

28,377 posts

291 months

Friday 5th September 2003
quotequote all
Have you run this code in a service before? I have found that code that works perfectly well in user mode suddenly encounters a world of trouble once inside the IIS service...

Have you considered re-implementing the functionality to avoid the need to use the DLL entirely? Might be easier in the long run..

tim_s

Original Poster:

299 posts

261 months

Saturday 6th September 2003
quotequote all
yeah i tried user impersonation but couldn't get it to work. when i changed machine.config it just crashed. i tried using domain accounts & local accounts - all with admin privilidges.

the dll i'm calling is written by a third party company and would be far too costly to rewrite.

tim_s

Original Poster:

299 posts

261 months

Wednesday 10th September 2003
quotequote all
i've finally found a way around this!!!

i created a console app which accepts paramters via the command line and intern calls the required dlls. i can then start a new process using system.diagnostics in my page to call the console app.