Browse Source

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
pull/716/head
Matt Ward 10 years ago
parent
commit
761f14e419
  1. 40
      src/Main/Base/Project/Designer/TypeResolutionService.cs

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

@ -411,9 +411,11 @@ namespace ICSharpCode.SharpDevelop.Designer @@ -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 @@ -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;
}
}
}
}

Loading…
Cancel
Save