Create mdb file to debug managed DLL in Unity

Viewed 2343

I'm trying to debug my managed DLL within Unity. It used to work fine on Unity 2018.x

Now I have Unity 2019.3 and I can't debug anymore (my DLLs are working fine I just can't debug them).

My DLL and its pdb file are in the Assets folder. That used to be enough to be able to debug them.

Reading this documentation : https://docs.unity3d.com/Manual/UsingDLL.html, I'm trying to create the mdb file.

First issue, the documentation says I have to pass the .pdb file as a parameter while most links on google say to pass the .dll

This link also states that I should change the working directory of my .bat file to be able to use pdb2mdb.exe : https://answers.unity.com/questions/294195/pdb2mdb-usage-error-from-command-line.html

Here is my code:

set PathToLib="Libraries\"
if exist Libraries\LibBDD.dll  (
    echo Before switching directory for my lib %CD%
    cd %PathToLib% 
    echo new directory %CD%
    @pause
    "C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0\pdb2mdb.exe" LibBDD.dll

    @pause
    cd ..\..\..\..\..\
    echo LibBDD done, new directory %CD%
    )

First of all I'm not sure if my CD command is working since the path remains the same. But I don't get any exception.

With this code I get:

Fatal error: Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6 à Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata(BitAccess bits) à Microsoft.Cci.Pdb.PdbFunction..ctor(String module, ManProcSym proc, BitAccess bits) à Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions(String module, BitAccess bits, UInt32 limit, Boolean readStrings) à Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule(BitAccess bits, DbiModuleInfo info, IntHashTable names, ArrayList funcList, Boolean readStrings, MsfDirectory dir, Dictionary`2 nameIndex, PdbReader reader) à Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, BitAccess bits, Boolean readAllStrings) à Pdb2Mdb.Driver.Convert(AssemblyDefinition assembly, Stream pdb, MonoSymbolWriter mdb)

Without the CD I get:

Mono pdb to mdb debug symbol store converter Usage: pdb2mdb assembly

I'm using Visual Studio 2019 Community.

I'm not sure what I am doing wrong and why I can't debug anymore in Unity. I've tried to add the csproj to the solution in VS but it doesn't do the trick anymore, the symbols are not loaded.

1 Answers

Looks like something changed in 2019.3 and for some reason Unity no longer generates the mdb files automatically.

The solution is to set your pdb's to portable instead of full which the the default you can do this by following the instructions from here. After this you no longer have any need for the mdb files.

Step by step instructions from the link above:

  1. In Solution Explorer, select the project.

  2. Select the Properties icon (or press Alt+Enter).

  3. In the side pane, choose Build (or Compile in Visual Basic).

  4. In the Configuration list, choose Debug or Release.

  5. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

  6. In the Debugging information list (or the Generate debug info list in Visual Basic), choose Portable.

  7. Build your project.

The compiler creates the symbol file(s) in the same folder as the executable or the main output file.

You can also read about it here and here

Related