From 761f14e419dc96a45c06906cb0f3b9674b6c0c77 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 2 Nov 2015 17:43:30 +0000 Subject: [PATCH] Fix WinForms designer not resolving OxyPlot assembly. With an OxyPlot.WindowsForms.PlotView on the form on re-opening the form in the designer you would see the following error message and the form would not be displayed: Could not find type 'OxyPlot.WindowsForms.PlotView' The PlotView type was being resolved correctly by the TypeResolutionService to the OxyPlot.WindowsForms assembly but getting the type required OxyPlot.dll to be resolved which was not being done. Fixes #713 --- .../Project/Designer/TypeResolutionService.cs | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Main/Base/Project/Designer/TypeResolutionService.cs b/src/Main/Base/Project/Designer/TypeResolutionService.cs index dffe5ab729..f69bff6d15 100644 --- a/src/Main/Base/Project/Designer/TypeResolutionService.cs +++ b/src/Main/Base/Project/Designer/TypeResolutionService.cs @@ -411,9 +411,11 @@ namespace ICSharpCode.SharpDevelop.Designer ITypeDefinition definition = ReflectionHelper.ParseReflectionName(name) .Resolve(compilation).GetDefinition(); if (definition != null) { - Assembly assembly = LoadAssembly(definition.ParentAssembly); - if (assembly != null) { - type = assembly.GetType(name, false, ignoreCase); + using (var resolver = new ProjectAssemblyResolver(compilation, this)) { + Assembly assembly = LoadAssembly(definition.ParentAssembly); + if (assembly != null) { + type = assembly.GetType(name, false, ignoreCase); + } } } } @@ -582,5 +584,37 @@ namespace ICSharpCode.SharpDevelop.Designer } return lastAssembly; } + + class ProjectAssemblyResolver : IDisposable + { + readonly ICompilation compilation; + readonly TypeResolutionService typeResolutionService; + + public ProjectAssemblyResolver(ICompilation compilation, TypeResolutionService typeResolutionService) + { + this.compilation = compilation; + this.typeResolutionService = typeResolutionService; + AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; + } + + public void Dispose() + { + AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve; + } + + Assembly AssemblyResolve(object sender, ResolveEventArgs args) + { + try { + IAssembly assembly = compilation.Assemblies + .FirstOrDefault(asm => asm.FullAssemblyName == args.Name); + if (assembly != null) { + return typeResolutionService.LoadAssembly(assembly); + } + } catch (Exception ex) { + LoggingService.Error(ex); + } + return null; + } + } } }