T
Tester
Hi all,
I have the following situation. I create AppDomains on demand to host
winform based controls from C++ host. I'm using .NET 1.1.
I tried to do AppDomain.Unload from background thread to free up the main
GUI thread and make it more responsive.
When I try this, I get the exception, listed below, always on the 3rd
AppDomain and control creation.
I tried getting SystemEvents through reflection and calling Shutdown
manually. This delays the problem. It almost doesn't happen, but still
re-appears
sometimes.
This doesn't reproduce in .NET 2.0 alpha.
Is there any way I can work around this bug/limitation?
I also would like to know what is being null inside the
UnsafeNativeMethods.CreateWindowEx or under what conditions.
Maybe I can work around the problem.
Thank you in advance for any help on this
Exception trace:
------------------
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.TypeInitializationException: The
type initializer for "System.Drawing.SafeNativeMethods" threw an
exception. ---> System.NullReferenceException: Object reference not set to
an instance of an object.
at Microsoft.Win32.UnsafeNativeMethods.CreateWindowEx(Int32 exStyle,
String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y,
Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef
hInst, Object pvParam)
at Microsoft.Win32.SystemEvents.CreateBroadcastWindow()
at Microsoft.Win32.SystemEvents.Initialize()
at Microsoft.Win32.SystemEvents.EnsureSystemEvents(Boolean requireHandle,
Boolean throwOnRefusal)
at Microsoft.Win32.SystemEvents.AddEventHandler(Int32 key, Delegate
value)
at Microsoft.Win32.SystemEvents.add_EventsThreadShutdown(EventHandler
value)
at System.Drawing.SafeNativeMethods.Initialize()
at System.Drawing.SafeNativeMethods..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.get_ThreadData()
at System.Drawing.SystemBrushes.FromSystemColor(Color c)
at System.Drawing.SystemBrushes.get_Window()
at
System.Windows.Forms.DataGridTableStyle.get_DefaultAlternatingBackBrush()
at System.Windows.Forms.DataGridTableStyle..ctor(Boolean
isDefaultTableStyle)
at System.Windows.Forms.DataGrid..ctor()
at DotNetControls.MainControl.InitializeComponent()
at DotNetControls.MainControl..ctor()
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder
binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(String assemblyName, String typeName,
Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
CultureInfo culture, Object[] activationAttributes, Evidence securityInfo,
StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String
typeName)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(Met
hodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessa
ge msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String
typeName)
at Adapter.CreateApp() in ...
I have the following situation. I create AppDomains on demand to host
winform based controls from C++ host. I'm using .NET 1.1.
I tried to do AppDomain.Unload from background thread to free up the main
GUI thread and make it more responsive.
When I try this, I get the exception, listed below, always on the 3rd
AppDomain and control creation.
I tried getting SystemEvents through reflection and calling Shutdown
manually. This delays the problem. It almost doesn't happen, but still
re-appears
sometimes.
This doesn't reproduce in .NET 2.0 alpha.
Is there any way I can work around this bug/limitation?
I also would like to know what is being null inside the
UnsafeNativeMethods.CreateWindowEx or under what conditions.
Maybe I can work around the problem.
Thank you in advance for any help on this
Exception trace:
------------------
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.TypeInitializationException: The
type initializer for "System.Drawing.SafeNativeMethods" threw an
exception. ---> System.NullReferenceException: Object reference not set to
an instance of an object.
at Microsoft.Win32.UnsafeNativeMethods.CreateWindowEx(Int32 exStyle,
String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y,
Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef
hInst, Object pvParam)
at Microsoft.Win32.SystemEvents.CreateBroadcastWindow()
at Microsoft.Win32.SystemEvents.Initialize()
at Microsoft.Win32.SystemEvents.EnsureSystemEvents(Boolean requireHandle,
Boolean throwOnRefusal)
at Microsoft.Win32.SystemEvents.AddEventHandler(Int32 key, Delegate
value)
at Microsoft.Win32.SystemEvents.add_EventsThreadShutdown(EventHandler
value)
at System.Drawing.SafeNativeMethods.Initialize()
at System.Drawing.SafeNativeMethods..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.get_ThreadData()
at System.Drawing.SystemBrushes.FromSystemColor(Color c)
at System.Drawing.SystemBrushes.get_Window()
at
System.Windows.Forms.DataGridTableStyle.get_DefaultAlternatingBackBrush()
at System.Windows.Forms.DataGridTableStyle..ctor(Boolean
isDefaultTableStyle)
at System.Windows.Forms.DataGrid..ctor()
at DotNetControls.MainControl.InitializeComponent()
at DotNetControls.MainControl..ctor()
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder
binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes)
at System.Activator.CreateInstance(String assemblyName, String typeName,
Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args,
CultureInfo culture, Object[] activationAttributes, Evidence securityInfo,
StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String
typeName)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(Met
hodBase mb, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs)
at
System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessa
ge msg, Int32 methodPtr, Boolean fExecuteInContext)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String
typeName)
at Adapter.CreateApp() in ...