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

Commit

Permalink
Fix WinForms designer not resolving OxyPlot assembly.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrward committed Nov 2, 2015
1 parent ea71545 commit 761f14e
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/Main/Base/Project/Designer/TypeResolutionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ public Type GetType(string name, bool throwOnError, bool ignoreCase)
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);
}
}
}
}
Expand Down Expand Up @@ -582,5 +584,37 @@ static Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs args
}
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;
}
}
}
}

0 comments on commit 761f14e

Please sign in to comment.