【发布时间】:2016-11-08 21:21:39
【问题描述】:
我有一个主应用程序,它从它们编译的 dll 文件中加载驱动程序。我遇到了一个问题,我希望能够调试这些 dll 文件,但项目没有加载符号。
dll 文件是解决方案的一部分,但必须与主应用程序分开构建。然后主应用程序在运行时从一个目录加载这些 dll。我在这些加载的 dll 文件之一中遇到错误(不是异常,只是意外结果),但无法调试这些文件。谁能给我一个关于如何继续调试这些的想法?
编辑: 为了更好地了解如何在此处加载 dll,请参考主项目中的代码:
public List<BaseClass> getObjects(string objectName)
{
List<BaseClass> availableDrivers = new List<BaseClass>();
string currentDir = Directory.GetCurrentDirectory();
currentDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); //Use this to find path even when running as service
if (Directory.Exists(currentDir + "\\Objects"))
{
string[] files = Directory.GetFiles(currentDir + "\\Objects", "*.dll");
foreach (string file in files)
{
Console.WriteLine("LOOKING AT:"+ file);
try
{
Assembly dll = Assembly.LoadFrom(file);
Type[] types = dll.GetTypes(); // .Where(x => x.BaseType.Name == "BaseClass");
foreach (Type type in types)
{
if (type.BaseType != null && (type.BaseType.Name == "BaseClass" || type.BaseType.Name == "PeriodicBaseClass"))
{
BaseClass ClassObj = (BaseClass)Activator.CreateInstance(type);
if (objectName == "" || objectsName == ClassObj.Name)
{
availableDrivers.Add(ClassObj);
}
}
}
}
catch (Exception e)
{
Error.Log("Error reading driver:" + e.Message,MessageType.Error);
//Console.WriteLine("Error reading driver:" + e.Message);
}
}
}
return availableDrivers;
}
如您所见,当我运行程序本身时,驱动程序会通过检索其编译的 dll 文件来加载,当在 dll 代码中放置断点时,我会收到提示无法加载符号的消息。我已尝试检查 Debug>Windows>Modules,但由于未直接在应用程序中加载,因此 dll 没有显示在那里。
【问题讨论】:
-
documentation 有什么帮助吗?如果没有,具体来说,您的问题是什么?获取.pdb?让他们加载?在没有 .pdb 的情况下进行调试?
-
假设 Visual Studio,在
Modules窗口中,右键单击调试有问题的 dll 并选择Symbol load information...选项。这应该让您知道为什么没有加载符号(也许您启用了Just My Code选项?)。还有Load symbols的选项允许您手动指定pdb文件。 -
@Resistance,这个dll文件是什么,自定义类库还是其他?请确保在 TOOLS->Options->Debugging->Symbols 下启用符号服务器。另外,你真的把这个dll文件作为引用添加到你的项目中了吗?如果您将其添加为参考,请设置属性“copy local=true”。
-
@Resistance,你能分享一下关于这个问题的最新信息吗?
-
@JackZhai 我很抱歉。我会写一个答案。
标签: c# debugging visual-studio-2015 debug-symbols pdb-files