由于AssemblyResolve事件,在打开DataSet Visualizer时发生异常 [英] Exception on opening DataSet Visualizer due to the AssemblyResolve event

查看:138
本文介绍了由于AssemblyResolve事件,在打开DataSet Visualizer时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试在我的 .Net Core中的 DataSet DataTable 之一上使用放大玻璃时3.1 WPF项目我得到一个 System.IO.FileLoadException 并显示以下文本:


无法加载文件或程序集 DataSetVisualizer.DebuggeeSide,版本= 16.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a。一般异常(0x80131500)


堆栈跟踪:

 在System.Reflection.RuntimeAssembly.nLoad(AssemblyName文件名,字符串codeBase,RuntimeAssembly assemblyContext,StackCrawlMark& stackMark,布尔throwOnFileNotFound,AssemblyLoadContext assemblyLoadContext)在System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(Ass ;在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.ClrCustomVisualizer中的
Host.Create(String debuggeeSideVisualizerTypeName,String debuggeeSideVisualizerAssemblyName,String [] probePaths)

我缩小了原因问题归结为我最近实现的在运行时从子文件夹加载程序集的方法,这是我根据 Reza Aghaei

解决方案

这不是一种优雅的解决方案,但可以作为一种解除锁定的解决方法您的调试会话,将以下内容添加到 AssemblyResolve 事件处理程序的开头:

  #if调试
if(arg.Name.StartsWith( DataSetVisualizer))
重新转为空;
#endif


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆