3

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.

user2088807
  • 1,378
  • 2
  • 25
  • 47
  • Does this answer your question? [Variables are not behaving as expected](https://stackoverflow.com/questions/30282784/variables-are-not-behaving-as-expected) – michael_heath Apr 03 '20 at 01:09

1 Answers1

10

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

Bobby Tables
  • 2,953
  • 7
  • 29
  • 53
  • Also, note that it looks like simple "step into" does not work - I need to open the file with the function I am stepping into and place a breakpoint there. So if I place a breakpoint on this line: q.Enqueue(); I need to open the file with the Queue class from the library sources in the same VS instance and place a breakpoint there. Then even the regular step into works. This is rather complicated since I need to manually find that class in the sources, but makes sense, since the sources are in totally unrelated projects. Just to be sure though, is this expected behavior?) – TheSmokingGnu Sep 23 '20 at 10:44
  • Yes! This totally worked for me, thanks! Stepping into with F11 works fine too. – NightElfik Oct 22 '20 at 07:58
  • Thank you so much ! This fixed a long due that we had with VS 2022 and Unity 2021 – Sriram90 Sep 07 '22 at 12:17