Search code examples
c#debuggingvisual-studio-2015debug-symbolspdb-files

Unable to load symbols for dll in c# project


I have a main application which loads drivers from their compiled dll files. 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.

The dll files are part of the solution but have to be built separately from the main application. The main application then at runtime loads these dlls from a directory. I am having an error in one of these loaded dll files (not an exception, just unexpected results) but cannot debug the files. 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:

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. I have tried checking Debug>Windows>Modules but the dlls don't show up there due to not being loaded directly in the application.


Solution

  • 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.

    I then set the startup project to the console application and was able to step through the relevant files properly.