Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problems Debugging My Plugin Dlls In Visual Studio

Discussion in 'Scripting' started by AliCEYC, Nov 28, 2017.

  1. AliCEYC

    AliCEYC

    Joined:
    Jul 21, 2017
    Posts:
    3
    Unity 2017.1 Visual Studio 2015

    I have a Unity project in which we have organised much of the source code into multiple dlls. We build these dlls in Visual Studio 2015 C# using .NET Framework in debug build Target framework Unity 3.5 .net full Base Class Libraries and then we cut and paste our dlls and their corresponding pdbs into our Unity project as managed plugins to Assets/Plugins folder which we can then reference from our Unity project scripts.

    This works fine but I am having difficulty debugging the plugin dll code.

    After the dlls have been pasted in to the Assets/Plugins folder and you focus on Unity Editor, the Unity Editor generates the meta files then compiles the scripts - a message box appears saying - "Compiling Scripts" appears.

    Then, I have a script attached to a Master game object from which I call the dlls from my runtime. I open the master script in Visual Stuio and click "Attach to Unity"

    Then, in Visual Studio Main Menu/Debug/Windows/Modules, I try to load debugging symbols for each of my dlls but they do not load/open -. In VS symbol file browser, when I try to open my pdbs a Microsoft Visual Studio warning message appears saying "A matching symbol file was not found in this folder" - even though such a file exists in the folder

    After Googling my problem, one suggestion was to open the dll using Dumpbin utility with a command window passing \headers and look in the dll itself If OK for debugging should see lines saying -

    Debug Directories

    Time Type Size RVA Pointer
    -------- ------ -------- -------- --------
    58DB991A cv 11C 0000A69C 889C Format: RSDS, {93D09C3E-7159-40AD-AECD-2D146399E951}, 1, C:\Users\MyUser\Documents\***\**\***\Libraries\***\projectname\obj\Release\MyPlugin.pdb

    "If you cannot see lines similar to these then that dll has no debugging references."

    I can see these lines after I have built the dll in Visual Studio but before cutting and pasting to Unity Plugins folder.

    The issue is, on loading into Unity , Unity overwrites the dll (ie dot net assembly) and removes the debug lines. I can watch Unity do this to the dll in Windows (File) Explorer. The file's size changes and a new data modified. The only was to stop this is to manually make the dll Read Only in Windows (File) Explorer/Properties. Then Unity is unable to modify the fll (assembly) and I am then able to debug OK.

    Does anyone know how to stop Unity altering the dll and removing the debugging lines when I add the dll into my Plugins folder?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
    Pretty sure if you run the Unity editor, it actually long-term mounts all the DLLs you ask it to until you close the editor.

    This means you cannot modify those DLLs "in place" without closing and then reopening the editor. It is certainly this way on the MacOSX version and I suspect that it is even moreso true for Windows. I'm surprised the build-DLL doesn't fail because it cannot write to the DLL file that Unity has locked.

    The drill is to close Unity editor, rebuild your DLLs, copy them in, then reopen Unity editor for this sort of thing.
     
  3. AliCEYC

    AliCEYC

    Joined:
    Jul 21, 2017
    Posts:
    3
    KD Thanks for responding. Even if I follow your suggestion, however, Unity still overwrites the dlls on launching Unity Editor and removes the debugging lines. I can watch it do it in Windows (File) Explorer. I don't know how to to stop it doing that apart from marking the dlls as Read Only. It makes trying to debug the plugins somwewhat cumbersome and slows up development. Any ideas anyone would be welcome.
     
  4. indevious

    indevious

    Joined:
    Nov 29, 2017
    Posts:
    16
    First, install the Visual Studio Tools for Unity. Then configure debugging as described here (scroll down to the "To debug a managed DLL project used in your Unity project" section).

    In short:
    1. Install VSTU.
    2. Output or post-build-copy your built debug DLL and PDB to the Unity /Assets folder.
    3. If you now add a Class library project to your Unity-generated VS solution file it will be maintained even when Unity regenerates the project.
    4. Set breakpoints and Attach as normal.
     
  5. AliCEYC

    AliCEYC

    Joined:
    Jul 21, 2017
    Posts:
    3
    Hi indevious -Thanks for that suggestion _ I had read that and followed those steps however I tracked down the issue to be something else - viz....

    The assemblies were being overwritten because of the Unity Automatic API Updater feature. Because some of the code in my dlls is "obsolete" and I just clicked Yes every time I opened my Unity project at the API Update Required dialog, Unity then attempts to automatically update the assemblies with the latest code (which is why I could see the dlls file sizes changing in File Explorer) however, in doing so, it seems to lose the debugging lines I mentioned above. All I needed to do was to click No Thanks buttons instead (or, of course, find and fix the obsolete code in my dlls. Now debugs OK.

    Anyway thanks for your help.
     
  6. GLeBaTi

    GLeBaTi

    Joined:
    Jan 12, 2013
    Posts:
    47
    How i solve this problem:

    Properties->Build->Advanced->Debugging information choose Portable.
     
    Snubber likes this.
  7. Babybus_Study

    Babybus_Study

    Joined:
    Oct 31, 2016
    Posts:
    14
    Thanks, that works!