[Mono-devel-list] Questions on DllImport failures

Bernie Solomon bernard at ugsolutions.com
Thu Jul 31 18:58:58 EDT 2003


I have been looking at trying to get failed DllImports to raise the correct
exceptions (System.DllNotFoundException &
System.EntryPointNotFoundException) and have a couple of questions.

1) The obvious thing to do is just call mono_raise_exception with an
appropriate exception in mono_lookup_pinvoke_call. But that routine is in
loader.c which is in libmetadata which doesn't have access to the runtime
routines for creating and raising exceptions. In my tests I have moved the
routine to marshal.c (because that is where one caller is). Is this
reasonable? Also is raising the exception directly here reasonable - it is
the best place in order to get substitutions in the message. I did move the
mono_lookup_pinvoke_call in marshal.c to avoid a leak in case of the
exception being thrown.

2) What is the proper way to create the exception from C with a message with
subtitutions in it so it is localizable properly yet preserving the precise
methods in classes like DllNotFoundException which match Microsoft's - or
can a new constructor be added which can pass in the file name or entry
point so the formatting is done in C#? Or should it invoke a C# mono
specific helper to construct the exception doing the formatting in C#? I
note that FileNotFoundException builds the message in its Message get method
but that is not translateable the way it is done. These sort of messages are
much more useful with info about what was not found so I'd like to get this
info in if at all possible.

Thanks for any pointers on these.

Bernie Solomon




More information about the Mono-devel-list mailing list