Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-9999 : try to reuse loaded dll #14860

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 19 additions & 3 deletions src/DynamoPackages/PackageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,23 +713,39 @@ internal static AssemblyLoadingState TryMetaDataContextLoad(string filename,Meta
/// <summary>
/// Attempt to load a managed assembly in to LoadFrom context.
/// </summary>
/// <param name="filename">The filename of a DLL</param>
/// <param name="filePath">The filename of a DLL</param>
/// <param name="assem">out Assembly - the passed value does not matter and will only be set if loading succeeds</param>
/// <returns>Returns true if success, false if BadImageFormatException (i.e. not a managed assembly)</returns>
internal static bool TryLoadFrom(string filename, out Assembly assem)
internal static bool TryLoadFrom(string filePath, out Assembly assem)
{
try
{
assem = Assembly.LoadFrom(filename);
assem = Assembly.LoadFrom(filePath);
return true;
}
catch (FileLoadException e)
{
// If the exception is having HRESULT of 0x80131621 ( a dll with the same name is already loaded ), then we will attempt to use that loaded dll.
if (e.HResult == unchecked((int)0x80131621))
{
Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
string fileName = Path.GetFileNameWithoutExtension(filePath);
foreach (Assembly loadedAssembly in loadedAssemblies)
{
if (loadedAssembly.FullName.StartsWith(fileName, StringComparison.OrdinalIgnoreCase))
{
assem = loadedAssembly;
return true;
}
}
}

// If the exception is having HRESULT of 0x80131515, then we need to instruct the user to "unblock" the downloaded DLL.
if (e.HResult == unchecked((int)0x80131515))
{
throw new DynamoServices.AssemblyBlockedException(e.Message);
}

assem = null;
return false;
}
Expand Down
Loading