Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Debugging a managed DLL

Discussion in 'Scripting' started by dubrovkin, Aug 21, 2020.

  1. dubrovkin


    Jan 27, 2017

    I use the following products:
    1. Unity 2020.1.2f1
    2. Visual Studio 2019 16.7.2
    3. Visual Studio 2019 Tools for Unity
    In Visual Studio, I create a blank solution and call it Base. Then I add a class library project and call it Base. For the project, I install .NET Standard 2.0 as the target platform. Debugging information is automatically set to Portable. I add class MyUtils to the project:

    Code (CSharp):
    2. namespace Base
    3. {
    4.     public static class MyUtils
    5.     {
    6.         public static int add(int a,int b)
    7.         {
    8.             return a+b;
    9.         }
    10.     }
    11. }
    Then I build the project and get three files:
    1. Base.dll
    2. Base.pdb
    3. Base.deps.json
    Now I create a new Unity project and call it Test. I copy two files to the root of the project (to the Assets folder on the disk):
    1. Base.dll
    2. Base.pdb
    Although I didn't notice any difference from having the pdb file in the project. In the project settings I have installed:

    However, the library itself says:

    And this is a little scary since I installed .NET Standard 2.0. I add script Test to the project:

    Code (CSharp):
    2. using UnityEngine;
    4. public sealed class Test : MonoBehaviour
    5. {
    6.     void Start()
    7.     {
    8.         int a=1;
    9.         int b=2;
    10.         int c=Base.MyUtils.add(a,b);
    12.         Debug.Log(c);
    13.     }
    14. }
    I place this script on the camera. I put a breakpoint on the line with the called function and start debugging from Visual Studio:

    Switch Unity to debug mode and play. My breakpoint is triggered:

    But after pressing Step Into (F11), I don't go inside the function:

    What actions do I need to do so that I can debug the code by going inside functions?

    I was reading this documentation (section "Debug a DLL in your Unity project"). But something I still did not understand in which project where they add what and why the project file is added to the project in the screenshot, and the link that they provide tells about adding the project to the solution. So I tried it and it didn't work.
  2. Xepherys


    Sep 9, 2012
    If the DLL is, in fact, targeting NET4* and your Unity project is targeting NETSTANDARD2.0, you will likely not be able to step into the DLL, even with the PDB file.

    If the listing of NET4* is incorrect, make sure that the build of the DLL you are using was done in Debug. PDBs can be generated even with Release builds in the event that you want to be able to see calls to symbols from the library, but if it's built in Release, it also won't be available to step into.
  3. dubrovkin


    Jan 27, 2017
    Here is the content of the Base project file:

    Code (CSharp):
    2. <Project Sdk="Microsoft.NET.Sdk">
    4.     <PropertyGroup>
    5.         <TargetFramework>netstandard2.0</TargetFramework>
    6.         <RootNamespace>Base</RootNamespace>
    7.     </PropertyGroup>
    9. </Project>
    You can see that .NET Standard 2.0 is indicated. The assembly is done by Debug. Unity had .NET Standard 2.0 installed at the Api Compatibility Level. It's strange why Targets .NET 4.x is written on the library itself (when looking in Unity) in the Assembly info field. But I tried to switch the Unity project to .NET 4.x, debugging also skips the function. What to do?