Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by Johannes 1 · Dec 12, 2010 at 01:14 PM · monodevelopdebugging

How to debug external .net Dlls

Hi,

We are currently evaluating Unity 3.1 for our next project. As recommended in this posting, we moved all of our game code to a Visual Studio solution outside of the asset folder. This enables us to use namespaces and multiple projects inside of this one solution. The build target of the managed assembly is a folder in the Asset folder of our Unity project. This works fine, created scripts are available in the Unity editor and the managed dll can also be used when deploying the project for the web player.

However, I have found no way to debug the built dll. I tried to debug it by adding the vsproj created by Unity automatically to my custom solution as the startup project and starting Unity from MonoDevelop. I can debug and step through scripts inside Unity without any problems, but breakpoints in the files that are compiled to the external dll are never reached.

Is there a way to enable debugging for external, managed dlls? (Note: the .pdb file for the assemby is build and copied to the same destination as the corresponding dll inside the asset folder)

Being able to debug and step through our code is a crucial feature for us as it is a very convienient way to find and fix problems in the code.

Thanks in advance and with best regards,

Johannes

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Johan 2 · Mar 11, 2011 at 01:21 AM

Unfortunately Visual Studio does not support debugging Unity projects for the moment. However, since Unity 3.2 one can attach to the running Unity process from MonoDevelop. This does not have to be from your Unity solution, but from any external dll project that is being used in your solution.

The trick is to create an mdb file for the external assembly and place it in the same folder as the dll that you import into your assembly.

"C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0\pdb2mdb.exe" extlib.dll

1.)Set the output path of the mono external dll project to be somewhere in your asset folder. As a post build step, you can run pdb2mdb.exe to create the mdb file in the same folder.

2.)Attach to the Unity process.

3.)Set a breakpoint anywhere you like

4.) Now exercise the code by running your scene in the Unity Editor.

It should break in the external dll.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Nov 28, 2012 at 04:54 PM 0
Share

To confirm -- this is working for me with Unity 3.5.6, $$anonymous$$onoDevelop 2.8.2, and a DLL built with Visual Studio 2010 Express. Thank you!

avatar image yoyo · Dec 07, 2012 at 12:40 AM 1
Share

Correction, this doesn't work with DLLs containing coroutines (pdb2mdb.exe has issues with IEnumerator), but use Unity/Editor/Data/$$anonymous$$onoBleedingEdge/lib/mono/4.0/pdb2mdb.exe and it's all good.

avatar image yoyo · Dec 07, 2012 at 11:19 PM 0
Share

For more info see http://forum.unity3d.com/threads/161685-How-to-build-and-debug-external-DLLs

avatar image ettmetal · May 12, 2014 at 12:34 AM 0
Share

Sorry for the bump - but could someone please clarify how to go about adding a breakpoint in a dll?

avatar image avi9111 · Apr 03, 2016 at 08:09 AM 0
Share

I seems work, since It is now 2016 there are many information on the internet to tell someone to debug C# using vs #^%@^&%#^& but no one can clearly define how to debug dll I think you steps works, I will try

avatar image
0

Answer by taoa · Dec 12, 2010 at 03:01 PM

[Edit]It seems this doens't work with .NET dlls[/Edit]

I've made several external dlls myself to be used in Unity. I only made C++ dlls, but that should still apply to C# ones. Obviously you'll want to make debug builds of your dlls as you'll have way more information for debugging (but be careful as someone without Visual C++ or C# installed might not be able to get your dll to run properly. In this case, build your dll in Release mode for everyone and in Debug for yourself). Then run Unity, open your debugger (Visual C++ or C#), attach it to Unity (Debug->Attach to Process->Unity), open the files you need breakpoints in, see VS stop the process once those breakpoints are reached.

Again, I can't be 100% sure it'll work with C# dlls, as I only did that with C++ dlls, but I did get breakpoints working in VS C++ on dlls I made myself while they were being used in Unity.

Best of luck.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Johannes 2 · Dec 13, 2010 at 09:25 AM 0
Share

Unfortunately this does not seem to work with .net dlls. I just tried it, but breakpoints are never hit, even when I set the code type to managed. I think it has something to do with the way .net libs are used in Unity. I don't know how it works exactly, but these dlls are interpreted by the mono runtime can also be compiled into a web player package.

I think since .net dlls are interpreted by mono, visual studio does not know what C# code is currently used by the process. This is also described here: http://answers.unity3d.com/questions/23933/how-to-debug-c-dll-code/24108#24108

avatar image taoa · Dec 13, 2010 at 04:34 PM 0
Share

Quite unfortunate. Unless you want to consider writing your scripts in C++? You might win a few FPS that way :)

avatar image Johannes 2 · Dec 14, 2010 at 09:05 AM 1
Share

Native code is not an option for us, since we want to deploy our project for the webplayer and C++ Code can not be used there.

And to be honest, I happily sacrifice a few FPS for the comfort of C# coding ;-) $$anonymous$$y current solution is to leave all scripts in the unity asset folder, but create a custom solution. This way I can have namespaces (except for $$anonymous$$onoBehaviours), multiple projects AND debugging in $$anonymous$$onoDevelop.

Of course an external dll would be better for reusabily and SVN (no meta files), but I won't sacrifice the ability to step through my code for that.

avatar image yoyo · Dec 07, 2012 at 11:20 PM 0
Share

It does work with .NET DLLs -- working fine for me with Unity 3.5.6 and Windows 7. $$anonymous$$ore details here -- http://forum.unity3d.com/threads/161685-How-to-build-and-debug-external-DLLs

avatar image
0

Answer by t-brjon · Jun 24, 2013 at 06:07 PM

I can confirm that this works with Visual Studio 2012, Unity 4.1.5f1 and Windows 8, with .Net DLLs.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Jun 24, 2013 at 06:15 PM 0
Share

@t-brjon, are you debugging with Visual Studio, or just editing your script files? If you are debugging, are you using the UnityVS extension from Syntax Tree? (http://unityvs.com)

avatar image t-brjon · Jun 24, 2013 at 06:28 PM 0
Share

I am debugging using $$anonymous$$onoDevelop. I haven't tried UnityVS yet.

I forgot to mention that pdb2mdb.exe needs to be run from the directory that the dll file is in... I had problems with that.

I ended up using post build events as covered here: http://www.youtube.com/watch?v=fphydfXBGW4

I couldn't get pdb2mdb to run from my Assets directory, so I modified the post-build events to:

"C:\Program Files (x86)\Unity\Editor\Data\$$anonymous$$ono\lib\mono\2.0\pdb2mdb.exe" "$(TargetName).dll" echo f | xcopy "$(TargetPath)" "$(ProjectDir)....\Assets\Plugins" /Y echo f | xcopy "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)....\Assets\Plugins" /Y echo f | xcopy "$(TargetDir)$(TargetName).dll.mdb" "$(ProjectDir)....\Assets\Plugins" /Y

Note that my VS solution is two directories below the Assets folder.

avatar image yoyo · Jun 24, 2013 at 06:32 PM 0
Share

Oh, ok, when you said "works with Visual Studio" I thought maybe you'd found a way to debug with VS, now I understand. Thanks for letting us know it's working in Unity 4.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Monodevelop 3 + debugging 0 Answers

Why does the debugger suddenly stop working 2 Answers

MonoDevelop Breakpoints don't stop execution 0 Answers

debugger halt after start(), can only resume in update 0 Answers

Could not connect to debugger 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges