简体   繁体   English

无法在c#项目中加载dll的符号

[英]Unable to load symbols for dll in c# project

I have a main application which loads drivers from their compiled dll files. 我有一个主应用程序,从其编译的DLL文件加载驱动程序。 I am running into a problem where I want to be able to debug these dll files but the symbols are not being loaded by the project. 我遇到了一个问题,我想能够调试这些DLL文件,但项目没有加载符号。

The dll files are part of the solution but have to be built separately from the main application. dll文件是解决方案的一部分,但必须与主应用程序分开构建。 The main application then at runtime loads these dlls from a directory. 然后,主应用程序在运行时从目录加载这些dll。 I am having an error in one of these loaded dll files (not an exception, just unexpected results) but cannot debug the files. 我在其中一个加载的DLL文件中出错(不是例外,只是意外结果)但无法调试文件。 Can anyone give me an idea on how to proceed with debugging these? 谁能让我知道如何进行这些调试?

EDIT: To give a better idea of how the dlls are loaded here is the code from the main project: 编辑:为了更好地了解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;
}

So as you can see, when I run the program itself the drivers get loaded by retrieving their compiled dll files and when putting breakpoints in the dll code I get the message saying symbols cannot be loaded. 所以你可以看到,当我运行程序本身时,驱动程序通过检索它们编译的dll文件来加载,当在dll代码中放置断点时,我得到消息说无法加载符号。 I have tried checking Debug>Windows>Modules but the dlls don't show up there due to not being loaded directly in the application. 我已经尝试检查Debug> Windows> Modules但由于没有直接在应用程序中加载,dll不会显示在那里。

If the dlls in question are debug versions (that is, they were compiled for debugging) and their current .pdb files are in the same directory, you should be able to step through them just as if they were in your own project. 如果有问题的dll是调试版本(也就是说,它们是为了调试而编译的),并且它们当前的.pdb文件位于同一目录中,那么您应该能够逐步完成它们,就像它们在您自己的项目中一样。

The other alternative is to open the solution that builds these dll and debug it by attaching to the process of the program you are running. 另一种方法是打开构建这些dll的解决方案,并通过附加到正在运行的程序的进程来调试它。

https://msdn.microsoft.com/en-us/library/3s68z0b3.aspx https://msdn.microsoft.com/en-us/library/3s68z0b3.aspx

So I ended up solving this problem. 所以我最终解决了这个问题。 The way I did this was create a small console application in the solution that runs the same methods as the main application but right from the projects in the solution instead of loading the dlls dynamically. 我这样做的方法是在解决方案中创建一个小型控制台应用程序,它运行与主应用程序相同的方法,但是直接来自解决方案中的项目,而不是动态加载dll。

I then set the startup project to the console application and was able to step through the relevant files properly. 然后,我将启动项目设置为控制台应用程序,并能够正确地逐步执行相关文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM