|
|
@ -479,37 +479,38 @@ namespace ICSharpCode.FormsDesigner |
|
|
|
|
|
|
|
|
|
|
|
appDomainHost.SelectionChanged -= new EventHandlerProxy(SelectionChangedHandler); |
|
|
|
appDomainHost.SelectionChanged -= new EventHandlerProxy(SelectionChangedHandler); |
|
|
|
|
|
|
|
|
|
|
|
appDomainHost.DesignSurfaceUnloaded += delegate { |
|
|
|
appDomainHost.DesignSurfaceUnloaded += new EventHandlerProxy( |
|
|
|
ServiceContainer serviceContainer = appDomainHost.GetService(typeof(ServiceContainer)) as ServiceContainer; |
|
|
|
delegate { |
|
|
|
if (serviceContainer != null) { |
|
|
|
ServiceContainer serviceContainer = appDomainHost.GetService(typeof(ServiceContainer)) as ServiceContainer; |
|
|
|
// Workaround for .NET bug: .NET unregisters the designer host only if no component throws an exception,
|
|
|
|
if (serviceContainer != null) { |
|
|
|
// but then in a finally block assumes that the designer host is already unloaded.
|
|
|
|
// Workaround for .NET bug: .NET unregisters the designer host only if no component throws an exception,
|
|
|
|
// Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
|
|
|
|
// but then in a finally block assumes that the designer host is already unloaded.
|
|
|
|
// when any component throws an exception.
|
|
|
|
// Thus we would get the confusing "InvalidOperationException: The container cannot be disposed at design time"
|
|
|
|
|
|
|
|
// when any component throws an exception.
|
|
|
|
// See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
|
|
|
|
|
|
|
|
// Reproducible with a custom control that has a designer that crashes on unloading
|
|
|
|
// See http://community.sharpdevelop.net/forums/p/10928/35288.aspx
|
|
|
|
// e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx
|
|
|
|
// Reproducible with a custom control that has a designer that crashes on unloading
|
|
|
|
|
|
|
|
// e.g. http://www.codeproject.com/KB/toolbars/WinFormsRibbon.aspx
|
|
|
|
// We work around this problem by unregistering the designer host manually.
|
|
|
|
|
|
|
|
try { |
|
|
|
// We work around this problem by unregistering the designer host manually.
|
|
|
|
var services = (Dictionary<Type, object>)typeof(ServiceContainer).InvokeMember( |
|
|
|
try { |
|
|
|
"Services", |
|
|
|
var services = (Dictionary<Type, object>)typeof(ServiceContainer).InvokeMember( |
|
|
|
BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic, |
|
|
|
"Services", |
|
|
|
null, serviceContainer, null); |
|
|
|
BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic, |
|
|
|
foreach (var pair in services.ToArray()) { |
|
|
|
null, serviceContainer, null); |
|
|
|
if (pair.Value is IDesignerHost) { |
|
|
|
foreach (var pair in services.ToArray()) { |
|
|
|
serviceContainer.GetType().InvokeMember( |
|
|
|
if (pair.Value is IDesignerHost) { |
|
|
|
"RemoveFixedService", |
|
|
|
serviceContainer.GetType().InvokeMember( |
|
|
|
BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, |
|
|
|
"RemoveFixedService", |
|
|
|
null, serviceContainer, new object[] { pair.Key }); |
|
|
|
BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, |
|
|
|
|
|
|
|
null, serviceContainer, new object[] { pair.Key }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
LoggingService.Error(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
|
|
|
|
LoggingService.Error(ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
appDomainHost.DisposeDesignSurface(); |
|
|
|
appDomainHost.DisposeDesignSurface(); |
|
|
|
} catch (ExceptionCollection exceptions) { |
|
|
|
} catch (ExceptionCollection exceptions) { |
|
|
@ -600,8 +601,6 @@ namespace ICSharpCode.FormsDesigner |
|
|
|
// This is required on Vista, I don't know why it works correctly in XP
|
|
|
|
// This is required on Vista, I don't know why it works correctly in XP
|
|
|
|
CustomWindowsFormsHost designView = WrapInCustomHost(appDomainHost.DesignSurfaceView, enableFontInheritance: false); |
|
|
|
CustomWindowsFormsHost designView = WrapInCustomHost(appDomainHost.DesignSurfaceView, enableFontInheritance: false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.UserContent = designView; |
|
|
|
this.UserContent = designView; |
|
|
|
LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + appDomainHost.DesignSurfaceName); |
|
|
|
LoggingService.Debug("FormsDesigner loaded, setting ActiveDesignSurface to " + appDomainHost.DesignSurfaceName); |
|
|
|
appDomainHost.ActivateDesignSurface(); |
|
|
|
appDomainHost.ActivateDesignSurface(); |
|
|
|