调试动态加载的程序集
我正在调试使用 Assembly 动态加载的程序集.Load(Byte[]),但我遇到了一些问题。
首先,我无法移动 Visual Studio 2010 中的黄色箭头以进入其他代码行,并且在尝试快速监视时出现异常(“无法在对象实例上找到方法。”)来自第三方库的对象(例如来自 Infragistics 的控件。)
Dim data = My.Computer.FileSystem.ReadAllBytes(file.FullName)
Assembly.Load(data)
当使用 Assembly.Load(String),一切正常很好,没有任何问题。
Assembly.Load(IO.Path.GetFileNameWithoutExtension(file.Name))
知道为什么行为如此不同吗?无论如何要解决这个问题吗?
我尝试使用 Assembly.Load(byte[].byte[]) 加载程序集的调试符号,但在尝试从第三方库调试对象时仍然遇到异常。
I am debugging an assembly which I loaded dynamically with Assembly.Load(Byte[]), but I am facing some problems.
First of all, I can't move the yellow arrow in Visual Studio 2010 to step into other lines of code, and also I am getiing exceptions ("Cannot find the method on the object instance.") when trying to do a quick watch on objects from a third party library (controls from Infragistics for example.)
Dim data = My.Computer.FileSystem.ReadAllBytes(file.FullName)
Assembly.Load(data)
When using Assembly.Load(String), everything works fine, and there are no problems.
Assembly.Load(IO.Path.GetFileNameWithoutExtension(file.Name))
Any idea why the behaviour is that much different? Anyway to fix this?
I tried loading the debugging symbols for my assembly with Assembly.Load(byte[]. byte[]), but I still get exceptions when trying to debug objects from third party libraries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
程序集的调试符号未加载到应用程序域中。当您使用字符串类型时,.NET 会自动在您指定的文件名旁边查找 .PDB。
要从字节数组加载程序集及其符号,请使用
Assembly。 Load(byte[], byte[])
,如下所示:The debug symbols for your assembly are not being loaded into the application domain. When you use the string variety, .NET automatically looks for a .PDB alongside the filename you specify.
To load an assembly and its symbols from byte arrays, use
Assembly.Load(byte[], byte[])
, like so:当您向它传递一个字节数组时,无法知道它来自哪个文件(或者它是否来自文件),因此它无法使用源代码行信息找到 PDB 文件。
您可以通过将
byte[]
保存为文件并确保它有一个具有相同文件名的 PDB 来解决此问题。When you pass it an array of bytes there's no way to know what file it comes from (or if it even comes from a file) so it can't locate the PDB file with the source code line information.
You can fix this by saving the
byte[]
as a file and making sure there's a PDB for it with the same file name.