runtime: ICorDebugManagedCallback::DebuggerError when unloading AssemblyLoadContext
Running the following code in VS d16.5 typically fails with an error dialog due to the CLR’s debugging interfaces returning DebuggerError with the error set to E_INVALIDARG.
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Loader;
namespace PlugInTest
{
class Program
{
//TODO: insert absolute path to managed dll
static string pluginPath = @"C:\MyPlugin.dll";
static AssemblyLoadContext AssemblyLoadContext;
static Assembly Assembly;
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Load()
{
AssemblyLoadContext = new AssemblyLoadContext("PluginLoader", true);
Assembly = AssemblyLoadContext.LoadFromAssemblyPath(pluginPath);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static WeakReference Unload()
{
Assembly = null;
AssemblyLoadContext.Unload();
WeakReference weakRef = new WeakReference(AssemblyLoadContext);
AssemblyLoadContext = null;
return weakRef;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test()
{
WeakReference weakRef;
{
Load();
weakRef = Unload();
}
while (weakRef.IsAlive)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
Console.WriteLine("Finished Test");
}
[MethodImpl(MethodImplOptions.NoInlining)]
static void Main(string[] args)
{
Test();
Test();
Test(); //crashs here at GC.Collect
}
}
}
originally reported here: https://developercommunity.visualstudio.com/content/problem/698374/vs2019-and-fatal-error-has-occurred-and-debugging.html
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 27 (14 by maintainers)
This keeps happening for me on 3.1 on Mac with both vsmac and vscode, with 3.1.404 SDK.
@nxrighthere dotnet/coreclr#28023 is the PR that’s porting it to 3.1 (not 3.0). As for when, I’d expect 3.1.4, exact dates are shifting a bit looks like but it’s the April release. As I get more information I’ll let you know.
There is a small chance that the root issue is somewhere in the VS Debugger portion of the managed debugger that is shared between VS/VS Code, but I need somebody on the runtime to investigate and confirm/deny.
It doesn’t seem like a known issue, but I’ve tagged the diagnostics folks who might know more and would most likely do the investigations. Can you please create a new issue for your problem? It will be better than piggy backing on a closed issue.
@nxrighthere I just took a look at the release candidate for 3.1.4 and can confirm it contains the fix. However we are waiting for some teams to give their thumbs up for the release. Given the current situation worldwide we are trying to tread very carefully to make sure we don’t anything that might regress customers. After talking to the release team, it should be finalized soon but they can’t give me a date right now.
The fix got merged and will be available in 3.1.4