由于 AssemblyResolve 事件,打开 DataSet Visualizer 时出现异常 [英] Exception on opening DataSet Visualizer due to the AssemblyResolve event
问题描述
当我在我的 .Net Core 3.1 WPF 项目中尝试在我的 DataSet
或 DataTable
之一上使用放大镜时,我得到一个 System.IO.FileLoadException
带有以下文本:
无法加载文件或程序集DataSetVisualizer.DebuggeeSide,版本=16.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a".一般异常 (0x80131500)
堆栈跟踪:
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly assemblyContext, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)在 System.Reflection.Assembly.Load(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)在 System.Reflection.Assembly.Load(AssemblyName assemblyRef)在 Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost..ctor(String debuggeeSideVisualizerTypeName, String debuggeeSideVisualizerAssemblyName, String[] probePaths)在 Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.Create(String debuggeeSideVisualizerTypeName, String debuggeeSideVisualizerAssemblyName, String[] probePaths)
我将这个问题的原因缩小到我最近实现的在运行时从子文件夹加载程序集的方法,这是我根据 Reza Aghaei 的
这不是一个优雅的解决方案,但作为解除调试会话阻塞的解决方法,将以下内容添加到 AssemblyResolve
事件处理程序:
#if DEBUGif (arg.Name.StartsWith(DataSetVisualizer"))返回空;#万一
When trying to use the magnifing glasson one of my DataSet
or DataTable
in my .Net Core 3.1 WPF Project I get a System.IO.FileLoadException
with following text:
Could not load file or assembly 'DataSetVisualizer.DebuggeeSide, Version=16.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. General Exception (0x80131500)
Stack trace:
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly assemblyContext, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost..ctor(String debuggeeSideVisualizerTypeName, String debuggeeSideVisualizerAssemblyName, String[] probePaths)
at Microsoft.VisualStudio.DebuggerVisualizers.DebuggeeSide.Impl.ClrCustomVisualizerDebuggeeHost.Create(String debuggeeSideVisualizerTypeName, String debuggeeSideVisualizerAssemblyName, String[] probePaths)
I narrowed the cause for this problem down to my recently implemented method to load assemblies from subfolders at runtime, which I wrote based on Reza Aghaei's answer on my last question.
In narrowed it down to the subscription on the AppDomain.CurrentDomain.AssemblyResolve
event, but couldn't find a way to solve it yet.
AppDomain.CurrentDomain.AssemblyResolve += (obj, arg) =>
{
var name = $"{new AssemblyName(arg.Name).Name}.dll";
var assemblyFile = referenceFiles.Where(x => x.EndsWith(name))
.FirstOrDefault();
if (assemblyFile != null)
return Assembly.LoadFrom(assemblyFile);
throw new Exception($"'{name}' Not found");
};
It doesn't matter if I am trying to view the DataSet
in one of the loaded assemblies or the startup application.
I would like to keep working with this method to load assemblies at runtime, but since I am working with a lot of DataSets
being able to use the DataSet Visualizer is crucial for me.
Any suggestions?
edit: usage of dataset visualizer during debugging:
Not an elegant solution, but as a workaround to unblock your debugging sessions, add the following to the beginning of the AssemblyResolve
event handler:
#if DEBUG
if (arg.Name.StartsWith("DataSetVisualizer"))
return null;
#endif
这篇关于由于 AssemblyResolve 事件,打开 DataSet Visualizer 时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!