Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
41 changes: 35 additions & 6 deletions src/ExtensionManager.Vsix.Shared/ExtensionManagerPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,47 @@ async void OnHandleCommand(object sender, EventArgs e)

file static class AssemblyResolver
{
[ThreadStatic]
private static int _nestingCount;

public static void Initialize()
=> AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;

private static Assembly? OnAssemblyResolve(object sender, ResolveEventArgs e)
{
var assemblyName = new AssemblyName(e.Name).Name;
var currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyPath = Path.Combine(currentFolder, assemblyName + ".dll");
// Prevent infinite recursion by checking if we're already inside this resolver
if (_nestingCount > 0)
return null;

if (File.Exists(assemblyPath))
return Assembly.LoadFile(assemblyPath);
_nestingCount++;
try
{
var requestedAssembly = new AssemblyName(e.Name);
var assemblyName = requestedAssembly.Name;
var currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var assemblyPath = Path.Combine(currentFolder, assemblyName + ".dll");

return null;
if (!File.Exists(assemblyPath))
return null;

var onDiskAssembly = AssemblyName.GetAssemblyName(assemblyPath);

// Only load if versions match - return null if they don't to allow other resolvers to try
if (requestedAssembly.Version != null &&
onDiskAssembly.Version != requestedAssembly.Version)
return null;

return Assembly.LoadFile(assemblyPath);
}
catch
{
// Swallow all exceptions and return null to allow other resolvers to try
// or to let the CLR handle the failure in the standard way
return null;
}
finally
{
_nestingCount--;
}
}
}