Fix MEF loader issues with framework assemblies (#253)

This is fixing a crashing bug in previous check-in so I'm pushing in.  Please leave comments on the commit and email if there is feedback.

* Fix MEF loader issues with framework assemblies

* Fix broken test from changed behavior

* Fix braces to C# convention
This commit is contained in:
Karl Burtram
2017-02-23 19:18:43 -08:00
committed by GitHub
parent 206cde9a3e
commit 3516a05f80
2 changed files with 29 additions and 4 deletions

View File

@@ -29,6 +29,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Extensibility
public static ExtensionServiceProvider CreateDefaultServiceProvider()
{
// only allow loading MEF dependencies from our assemblies until we can
// better seperate out framework assemblies and extension assemblies
string[] inclusionList =
{
"microsoft.sqltools.credentials.dll",
"microsoft.sqltools.hosting.dll",
"microsoft.sqltools.servicelayer.dll"
};
string assemblyPath = typeof(ExtensionStore).GetTypeInfo().Assembly.Location;
string directory = Path.GetDirectoryName(assemblyPath);
@@ -38,13 +47,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Extensibility
List<Assembly> assemblies = new List<Assembly>();
foreach (var path in assemblyPaths)
{
// skip DLL files not in inclusion list
bool isInList = false;
foreach (var item in inclusionList)
{
if (path.EndsWith(item, StringComparison.OrdinalIgnoreCase))
{
isInList = true;
break;
}
}
if (!isInList)
{
continue;
}
try
{
assemblies.Add(
context.LoadFromAssemblyName(
AssemblyLoadContext.GetAssemblyName(path)));
}
catch (System.BadImageFormatException)
catch (Exception)
{
// we expect exceptions trying to scan all DLLs since directory contains native libraries
}