[Mono-list] In Linux, does Mono support OpenEventLog, ReadEventLog... functions in Advapi32.dll?

Jonathan Pryor jonpryor at vt.edu
Fri Nov 16 10:33:57 EST 2007


On Wed, 2007-11-14 at 11:49 -0800, yao2000 wrote:
> I am testing my code to open/read Windows eventlog. My code is written in
> C#, When I compile and run the code in Mono under Windows OS, the code works
> fine. But if I move the code to RH Linux, then compile by gmcs and run by
> mono, I get the error:
> 
> Unhandled Exception: System.DllNotFoundException: Advapi32.dll
> 
> 
> To call Win32 API from C#, the OpenEventLog() function is declared as below
> to map Win32 API.
> 
>         [DllImport("Advapi32.dll")]
>         public static extern int OpenEventLog(string server, // use local
> computer
>                         string EVENTLOG); // source name
> 
> Does Mono have not implemented EventLog operations in Linux yet?

So *you* are writing that P/Invoke declaration?  If so, that's the
problem -- no Unix platform provides ADVAPI32.DLL, hence the
DllNotFoundException.

Mono provides a runtime environment for executing .NET code, it does NOT
duplicate all of Win32 to permit portability of any random piece of .NET
code to non-Windows platforms.  (That's what the Wine project is for --
pity Mono doesn't currently execute under Wine....)

The fix to your problem is to not use ADVAPI32.DLL under non-Windows
platforms, and use an alternate.  Or better, use
System.Diagnostics.EventLog to deal with the event log instead of using
OpenEventLog() directly.  The downside is that under Linux the EventLog
class doesn't read dmesg(1) messages, but only messages created by other
Mono EventLog instances.

 - Jon




More information about the Mono-list mailing list