Browse Source

Add workaround to ICSharpCode.Core that makes assemblies in the LoadFrom context also available in the Load context. This fixes some problems using WPF or .NET remoting in SharpDevelop AddIns.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6054 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Daniel Grunwald 15 years ago
parent
commit
ccc4e24de9
  1. 23
      SharpDevelop.sln
  2. 9
      src/AddIns/Analysis/CodeAnalysis/Src/FxCopWrapper.cs
  3. 11
      src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs
  4. 1
      src/Main/Core/Project/ICSharpCode.Core.csproj
  5. 1
      src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs
  6. 50
      src/Main/Core/Project/Src/AddInTree/AddIn/AssemblyLocator.cs
  7. 1
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj
  8. 89
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

23
SharpDevelop.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.5950
# SharpDevelop 4.0.0.6050
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Main", "Main", "{256F5C28-532C-44C0-8AB8-D8EC5E492E01}"
ProjectSection(SolutionItems) = postProject
EndProjectSection
@ -16,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Bu @@ -16,11 +16,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop.Bu
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core.Tests", "src\Main\Core\Test\ICSharpCode.Core.Tests.csproj", "{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "src\Main\Core\Project\ICSharpCode.Core.csproj", "{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core.Presentation", "src\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj", "{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}"
@ -438,27 +433,27 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{F3 @@ -438,27 +433,27 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Analysis", "Analysis", "{F3
ProjectSection(SolutionItems) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "src\AddIns\Analysis\UnitTesting\UnitTesting.csproj", "{1F261725-6318-4434-A1B1-6C70CE4CD324}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQualityAnalysis", "src\AddIns\Analysis\CodeQuality\CodeQualityAnalysis.csproj", "{76DD1CC0-0D86-44A1-9BD6-D91F79807BC3}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeAnalysis", "src\AddIns\Analysis\CodeAnalysis\CodeAnalysis.csproj", "{3EAA45A9-735C-4AC7-A799-947B93EA449D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTesting", "src\AddIns\Analysis\UnitTesting\UnitTesting.csproj", "{1F261725-6318-4434-A1B1-6C70CE4CD324}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeCoverage", "src\AddIns\Analysis\CodeCoverage\Project\CodeCoverage.csproj", "{08CE9972-283B-44F4-82FA-966F7DFA6B7A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeAnalysis", "src\AddIns\Analysis\CodeAnalysis\CodeAnalysis.csproj", "{3EAA45A9-735C-4AC7-A799-947B93EA449D}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceAnalysis", "src\AddIns\Analysis\SourceAnalysis\SourceAnalysis.csproj", "{CE498514-D12D-4B6E-AE0E-FEC29BD43748}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeCoverage", "src\AddIns\Analysis\CodeCoverage\Project\CodeCoverage.csproj", "{08CE9972-283B-44F4-82FA-966F7DFA6B7A}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQualityAnalysis", "src\AddIns\Analysis\CodeQuality\CodeQualityAnalysis.csproj", "{76DD1CC0-0D86-44A1-9BD6-D91F79807BC3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SourceAnalysis", "src\AddIns\Analysis\SourceAnalysis\SourceAnalysis.csproj", "{CE498514-D12D-4B6E-AE0E-FEC29BD43748}"
ProjectSection(ProjectDependencies) = postProject
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {35CEF10F-2D4C-45F2-9DD1-161E0FEC583C}
EndProjectSection
@ -691,10 +686,6 @@ Global @@ -691,10 +686,6 @@ Global
{3DF4060F-5EE0-41CF-8096-F27355FD5511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DF4060F-5EE0-41CF-8096-F27355FD5511}.Release|Any CPU.Build.0 = Release|Any CPU
{3DF4060F-5EE0-41CF-8096-F27355FD5511}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5}.Release|Any CPU.Build.0 = Release|Any CPU
{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Release|Any CPU.Build.0 = Release|Any CPU
@ -848,7 +839,6 @@ Global @@ -848,7 +839,6 @@ Global
{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{35CEF10F-2D4C-45F2-9DD1-161E0FEC583C} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{AD6FAA08-D6F5-4DBA-AF85-F4DA9F40C3B5} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{C3CBC8E3-81D8-4C5B-9941-DCCD12D50B1F} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{B5F54272-49F0-40DB-845A-8D837875D3BA} = {256F5C28-532C-44C0-8AB8-D8EC5E492E01}
{DDE2A481-8271-4EAC-A330-8FA6A38D13D1} = {2A232EF1-EB95-41C6-B63A-C106E0C95D3C}
@ -933,5 +923,6 @@ Global @@ -933,5 +923,6 @@ Global
{08CE9972-283B-44F4-82FA-966F7DFA6B7A} = {F355E45F-F54F-4B42-8916-9A633A392789}
{3EAA45A9-735C-4AC7-A799-947B93EA449D} = {F355E45F-F54F-4B42-8916-9A633A392789}
{1F261725-6318-4434-A1B1-6C70CE4CD324} = {F355E45F-F54F-4B42-8916-9A633A392789}
{76DD1CC0-0D86-44A1-9BD6-D91F79807BC3} = {F355E45F-F54F-4B42-8916-9A633A392789}
EndGlobalSection
EndGlobal

9
src/AddIns/Analysis/CodeAnalysis/Src/FxCopWrapper.cs

@ -178,21 +178,12 @@ namespace ICSharpCode.CodeAnalysis @@ -178,21 +178,12 @@ namespace ICSharpCode.CodeAnalysis
setup.ApplicationBase = fxCopPath;
AppDomain domain = AppDomain.CreateDomain("FxCop Rule Loading Domain", AppDomain.CurrentDomain.Evidence, setup);
ResolveEventHandler onResolve = delegate(object sender, ResolveEventArgs args) {
if (args.Name == typeof(FxCopWrapper).Assembly.FullName) {
return typeof(FxCopWrapper).Assembly;
} else {
return null;
}
};
FxCopRule[] ruleList;
try {
AppDomain.CurrentDomain.AssemblyResolve += onResolve;
FxCopWrapper wrapper = (FxCopWrapper)domain.CreateInstanceFromAndUnwrap(typeof(FxCopWrapper).Assembly.Location, typeof(FxCopWrapper).FullName);
ruleList = wrapper.GetRuleListInstanceMethod(fxCopPath, ruleAssemblies);
} finally {
AppDomain.CurrentDomain.AssemblyResolve -= onResolve;
AppDomain.Unload(domain);
}

11
src/AddIns/Analysis/Profiler/Frontend/AddIn/Src/Views/ProfilerView.xaml.cs

@ -31,10 +31,7 @@ namespace ICSharpCode.Profiler.AddIn.Views @@ -31,10 +31,7 @@ namespace ICSharpCode.Profiler.AddIn.Views
public ProfilerView(ProfilingDataProvider provider)
{
// workaround for bug in .NET 4.0 Beta 1
AppDomain.CurrentDomain.AssemblyResolve += AppDomain_CurrentDomain_AssemblyResolve;
InitializeComponent();
AppDomain.CurrentDomain.AssemblyResolve -= AppDomain_CurrentDomain_AssemblyResolve;
this.provider = provider;
@ -67,14 +64,6 @@ namespace ICSharpCode.Profiler.AddIn.Views @@ -67,14 +64,6 @@ namespace ICSharpCode.Profiler.AddIn.Views
InitializeOldTabs();
}
System.Reflection.Assembly AppDomain_CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name == "ICSharpCode.Profiler.Controls, PublicKeyToken=null")
return typeof(QueryView).Assembly;
else
return null;
}
void TimeLineRangeChanged(object sender, RangeEventArgs e)
{
foreach (TabItem item in this.tabView.Items) {

1
src/Main/Core/Project/ICSharpCode.Core.csproj

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\AddInTree\AddIn\AddIn.cs" />
<Compile Include="Src\AddInTree\AddIn\AddInLoadException.cs" />
<Compile Include="Src\AddInTree\AddIn\AssemblyLocator.cs" />
<Compile Include="Src\AddInTree\AddIn\Codon.cs" />
<Compile Include="Src\AddInTree\AddIn\ComplexCondition.cs" />
<Compile Include="Src\AddInTree\AddIn\Condition.cs" />

1
src/Main/Core/Project/Src/AddInTree/AddIn/AddIn.cs

@ -89,6 +89,7 @@ namespace ICSharpCode.Core @@ -89,6 +89,7 @@ namespace ICSharpCode.Core
// However, we need to make sure we don't return before the dependencies are ready,
// so "bool dependenciesLoaded" must be volatile and set only at the very end of this method.
if (!dependenciesLoaded) {
AssemblyLocator.Init();
foreach (AddInReference r in manifest.Dependencies) {
if (r.RequirePreload) {
bool found = false;

50
src/Main/Core/Project/Src/AddInTree/AddIn/AssemblyLocator.cs

@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <author name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Reflection;
namespace ICSharpCode.Core
{
// Based on http://ayende.com/Blog/archive/2006/05/22/SolvingTheAssemblyLoadContextProblem.aspx
// This class ensures that assemblies loaded into the LoadFrom context are also available
// in the Load context.
static class AssemblyLocator
{
static Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
static bool initialized;
public static void Init()
{
lock (assemblies) {
if (initialized)
return;
initialized = true;
AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
lock (assemblies) {
Assembly assembly = null;
assemblies.TryGetValue(args.Name, out assembly);
return assembly;
}
}
static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
Assembly assembly = args.LoadedAssembly;
lock (assemblies) {
assemblies[assembly.FullName] = assembly;
}
}
}
}

1
src/Main/ICSharpCode.SharpDevelop.Dom/Project/ICSharpCode.SharpDevelop.Dom.csproj

@ -132,7 +132,6 @@ @@ -132,7 +132,6 @@
<Compile Include="Src\ReflectionLayer\ReflectionClass.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionEvent.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionField.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionLoader.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionMethod.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionParameter.cs" />
<Compile Include="Src\ReflectionLayer\ReflectionProperty.cs" />

89
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReflectionLayer/ReflectionLoader.cs

@ -1,89 +0,0 @@ @@ -1,89 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using System.Reflection;
namespace ICSharpCode.SharpDevelop.Dom
{
public sealed class ReflectionLoader : MarshalByRefObject
{
public override string ToString()
{
return "ReflectionLoader in " + AppDomain.CurrentDomain.FriendlyName;
}
public string LoadAndCreateDatabase(string fileName, string cacheDirectory)
{
try {
ReflectionProjectContent content = LoadProjectContent(fileName, new ProjectContentRegistry());
if (content == null)
return null;
return new DomPersistence(cacheDirectory, null).SaveProjectContent(content);
} catch (Exception ex) {
if (ex is FileLoadException) {
LoggingService.Info(ex);
} else {
LoggingService.Error(ex);
}
throw;
}
}
ReflectionProjectContent LoadProjectContent(string fileName, ProjectContentRegistry registry)
{
fileName = Path.GetFullPath(fileName);
LoggingService.Debug("Trying to load " + fileName);
Assembly assembly;
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += AssemblyResolve;
lookupDirectory = Path.GetDirectoryName(fileName);
try {
if (File.Exists(fileName)) {
assembly = Assembly.ReflectionOnlyLoadFrom(fileName);
return new ReflectionProjectContent(assembly, fileName, registry);
} else
throw new FileLoadException("Assembly not found.");
} catch (BadImageFormatException ex) {
LoggingService.Warn("BadImageFormat: " + fileName);
throw new FileLoadException(ex.Message, ex);
} finally {
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve -= AssemblyResolve;
lookupDirectory = null;
}
}
string lookupDirectory;
Assembly AssemblyResolve(object sender, ResolveEventArgs e)
{
AssemblyName name = new AssemblyName(e.Name);
LoggingService.Debug("ProjectContentRegistry.AssemblyResolve " + e.Name);
string path = Path.Combine(lookupDirectory, name.Name);
if (File.Exists(path + ".dll")) {
return Assembly.ReflectionOnlyLoadFrom(path + ".dll");
}
if (File.Exists(path + ".exe")) {
return Assembly.ReflectionOnlyLoadFrom(path + ".exe");
}
if (File.Exists(path)) {
return Assembly.ReflectionOnlyLoadFrom(path);
}
try {
LoggingService.Debug("AssemblyResolve trying ReflectionOnlyLoad");
return Assembly.ReflectionOnlyLoad(e.Name);
} catch (FileNotFoundException) {
LoggingService.Warn("AssemblyResolve: ReflectionOnlyLoad failed for " + e.Name);
// We can't get the assembly we want.
// But propably we can get a similar version of it.
DomAssemblyName fixedName = GacInterop.FindBestMatchingAssemblyName(e.Name);
LoggingService.Info("AssemblyResolve: FixedName: " + fixedName);
return Assembly.ReflectionOnlyLoad(fixedName.FullName);
}
}
}
}
Loading…
Cancel
Save