mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user