Exception in SafeNativeMethods
-
Hi! Sorry for posting in multiple boards, but my post in the C# board gave no replies what so ever, so I thought I give it a try here too. I´m working on a project where we are making a hook for an other software. Now we have encountered a problem and I would like some help on finding a work-around. When we are opening a new form in the hook an exception is thrown and the form is destroyed. The exception is a System.TypeInitializationException that says that "The type initializer for "System.Drawing.SafeNativeMethods" threw an exception. -->System.NullreferenceException: Object reference not set to an instance of an object". I have traced the exception into the InitializeComponent() method and it is thrown when the first component on the form is initialized. This exception does not appere every time, but once in a while. I can not see any real reason for the problem and we are not doing any different when it works and does not. I have searched the net and found others that have had the same problem, mut I have not found any good solution. The problem seems to be in GDI+, at least that is what how I have understod it when reading posts on other forums.. The application loading the hook is creating appDomains for all hooks so that it can unload them as it whishes, I think that this might be the root of the problem, or? We would really need to show this form, its for configuring the hook, and the main application really needs to unload the hooks now and then, so the problem is a fact. Is there any good work-around for this? Is there anything we can do to solve this problem without having to make changes in the main application? All help appriciated! Regards Mikael