Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 761f14e

Browse files
committed
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
1 parent ea71545 commit 761f14e

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

src/Main/Base/Project/Designer/TypeResolutionService.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,11 @@ public Type GetType(string name, bool throwOnError, bool ignoreCase)
411411
ITypeDefinition definition = ReflectionHelper.ParseReflectionName(name)
412412
.Resolve(compilation).GetDefinition();
413413
if (definition != null) {
414-
Assembly assembly = LoadAssembly(definition.ParentAssembly);
415-
if (assembly != null) {
416-
type = assembly.GetType(name, false, ignoreCase);
414+
using (var resolver = new ProjectAssemblyResolver(compilation, this)) {
415+
Assembly assembly = LoadAssembly(definition.ParentAssembly);
416+
if (assembly != null) {
417+
type = assembly.GetType(name, false, ignoreCase);
418+
}
417419
}
418420
}
419421
}
@@ -582,5 +584,37 @@ static Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs args
582584
}
583585
return lastAssembly;
584586
}
587+
588+
class ProjectAssemblyResolver : IDisposable
589+
{
590+
readonly ICompilation compilation;
591+
readonly TypeResolutionService typeResolutionService;
592+
593+
public ProjectAssemblyResolver(ICompilation compilation, TypeResolutionService typeResolutionService)
594+
{
595+
this.compilation = compilation;
596+
this.typeResolutionService = typeResolutionService;
597+
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
598+
}
599+
600+
public void Dispose()
601+
{
602+
AppDomain.CurrentDomain.AssemblyResolve -= AssemblyResolve;
603+
}
604+
605+
Assembly AssemblyResolve(object sender, ResolveEventArgs args)
606+
{
607+
try {
608+
IAssembly assembly = compilation.Assemblies
609+
.FirstOrDefault(asm => asm.FullAssemblyName == args.Name);
610+
if (assembly != null) {
611+
return typeResolutionService.LoadAssembly(assembly);
612+
}
613+
} catch (Exception ex) {
614+
LoggingService.Error(ex);
615+
}
616+
return null;
617+
}
618+
}
585619
}
586620
}

0 commit comments

Comments
 (0)