-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Unable to delete File (dll) after unloading context. #11408
Comments
Answered in https://github.com/dotnet/corefx/issues/19773#issuecomment-435888506 We should make sure to include this in the documentation for assembly unloading at https://docs.microsoft.com/en-us/ |
Closing this issue as we have already published a doc on unloading at https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability-howto |
Unfortunately Microsoft's example project also unable to delete dll after unloading. Console.WriteLine($"Unload success: {!hostAlcWeakRef.IsAlive}");
File.Delete(pluginFullPath); |
I had the same problem and I'm going to do more tests tonight. |
@masums @FrankDoersam I solved this problem using stream loading.Maybe it can solve your problem. if (!DynamicDlls.ContainsKey(path))
{
using (FileStream stream = new FileStream(path, FileMode.Open))
{
var assembly = LoadFromStream(stream);
var types = assembly.GetTypes();
for (int i = 0; i < types.Length; i++)
{
ClassMapping[types[i].Name] = assembly;
}
}
} It's ok. |
Thank you for your suggestion. But how it will load its dependencies. And
will we be able to delete them also after unload?
…On Wed, Aug 21, 2019 at 7:15 AM 东北亚 · 丧坤 ***@***.***> wrote:
@masums <https://github.com/masums> @FrankDoersam
<https://github.com/FrankDoersam> I solved this problem using stream
loading.Maybe it can solve your problem.
if (!DynamicDlls.ContainsKey(path))
{
using (FileStream stream = new FileStream(path, FileMode.Open))
{
var assembly = LoadFromStream(stream);
var types = assembly.GetTypes();
for (int i = 0; i < types.Length; i++)
{
ClassMapping[types[i].Name] = assembly;
}
}
}
It's ok.
But before you unload it, you have to clear the dictionary.
DynamicDlls.Clear(); (Note: Don't do it in the 'Main' method.)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/dotnet/coreclr/issues/20806?email_source=notifications&email_token=AANTGWFDC2563EBZ6XRK2HLQFSJK7A5CNFSM4GB2WXQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4YDXPA#issuecomment-523254716>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANTGWDQ2W2KBDV7SVAQDS3QFSJK7ANCNFSM4GB2WXQQ>
.
|
@masums Maybe using AssemblyDependencyResolver.
|
@masums Unwittingly, I found a solution to this. In the constructor if (arg == "Default")
{
Default.Resolving += Default_Resolving;
} In the class //Default will
private Assembly Default_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
{
return Load(arg2);
} protected override Assembly Load(AssemblyName assemblyName)
{
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
{
return Handler(assemblyPath);
}
return null;
} @janvorli I'm a little confused. If I use the Resolving event instead of implementing the Load method, it will also work. Load and Resolving have the same functionality? |
@vitek-karas can you please answer the question about Resolving event vs Load method? |
@masums I am sorry, I've missed your comment on this here. It should work, so let me try to figure out what's wrong. |
@janvorli I have an issue. I learned SOS debugging and printed out some information, but I don't know if it's useful? https://github.com/dotnet/coreclr/issues/26386 |
The Another difference is that the @NMSAzulX loading from memory should work, but there is a downside - it will not work with Ready2Run images (assemblies precompiled via |
@janvorli @vitek-karas Thank you very much.Will there be any documents coming out? |
Documentation about the |
@vitek-karas OK . |
Today I have tested https://github.com/dotnet/samples/tree/master/core/tutorials/Unloading this code again. Now it is working with the new release of .Net core 3.0.100. Delete is working for unloaded dll. May be It will also work for me if I update the framework version. |
Hello,
i could not delete a dll after unloading it.
Could you please fix this bug.
Code:
class SimpleUnloadableAssemblyLoadContext : AssemblyLoadContext
{
public SimpleUnloadableAssemblyLoadContext()
: base(isCollectible: true)
{
}
Thanks in advance.
Yours sincerely
Frank Dörsam
The text was updated successfully, but these errors were encountered: