I want to debug separate pieces of my application in Visual Studio 2012.
I have C# executable which works with Oracle.DataAccess dll. It works fine.
Within it IronPython runtime is invoked and it works fine too.
Within these IronPython modules object from main C# application is invoked and it works fine with Oracle dll.
If IronPython script is invoked standalone then it works fine and uses C# object fine as well.
However in this case C# object doesn't see Oracle dll.
To debug IronPython scripts I have to create separate Python solution so I cannot configure my C# solution. So I do not have control of C# references. GAC has right Oracle dll but how to tell C# dll to use it?
Vise versa if I'm in C# solution where I can manage the references then I cannot add py files and debug them.
In what way can I configure VS to be able to run/debug my application with dual entry C# or IronPython separately?
You can try replicating what "works for me". Create a solution containing:
python project (ironpython)
C# project
Add a reference to desired oracle library (Oracle.DataAccess.dll) to C# project using the standard VS mechanism. C# project should also contains a post build step to copy the resulting dll and pdb into the place where python script can find it. In my case root of the python project.
Your python project is selected as Startup Project.
I use Ctrl-F5 and F5 to start it. In both cases things work as expected.
In debug mode I am able to set and hit breakpoint in python and in referenced C# module. I can see the oracle library being loaded (Output window of debugger).
However:
The stack traces are C# only.
Visual Studio 2013 Update 4 together with PTVS 2.1 crashes on occasions when debugging.
Related
I have a solution primarily based on C# projects, but I will occasionally need to use libraries written in native c++. The way I have solved this is by having a native project that simply acts as a wrapper for a native library, in this case OpenCV (I know I could use EMGUCV directly in C#, but in my experience it has some bugs that I would like to avoid and this is more a proof of concept anyways). I then have a C++ CLR project that references the native wrapper, and finally a C# project referencing the C++ CLR project. Strictly speaking I could just reference OpenCV directly from the CLR project instead of having the native wrapper project, but I would like to organize it this way both to conform to how the rest of the solution is organized and because I might at some point want to have this structure for another reason.
The first problem with this approach is that I can't find a way for Visual Studio to automatically include the dll of the native wrapper in the final target directory. Referencing the native project from the CLR project works flawlessly and referencing the CLR project from the C# project is no problem, but when I build it won't run because the native dlls are not brought to the final target. I solved this by adding some post build actions to copy the native dll and pdb files. This works, and I'm able to run the code with no errors. However, I'm unable to debug the native project. I hit breakpoints in the C# project and CLR projects, but not the native project.
What I have tried:
In the C# project properties I have enabled the native code debugging option.
In the CLR project I have set debugging mode to mixed.
In the native project I have tried both native only and mixed debugging mode
In the C# project I have checked allow unsafe code
In visual studio under tools->options->debugging->general I have tried checking and unchecking use native compatibility mode and suppress jit optimization on module load.
I tried opening the native project in a separate visual studio instance to attach the debugger to the project running from the whole solution, but I was not allowed to do this as the solution debugger was already attached to that project. Someone suggested to do this, but didn't explain how this could be done.
The problem was that the C# project I referred to before was in itself a dll being called by another C# exe project. When I enabled native debugging for this project, everything worked as expected.
I have an un-managed WIN32 dll that was written in VC++ 6 and called from a C# application. I have the dll project in VS2010 and C# project in VS2017. Both project can run through under debug/release mode successfully.
I found there was something wrong with the arguments passed by C# to the dll and thus wanted to debug the dll project. Here is what I did.
Open both VS2010 dll and VS2017 C# project
Change both projects' debugger type to mixed.
Change both projects' property to enable un-managed code debugging (it's called native code in VS2017)
Set break points at the argument calculation inside the dll where I want to debug and the C## function where I called the dll
For both vs2017 and vs2010, under Tools>Options>Debugging>Symbols I define the path where .pdb files were generated for the dll project and Select "Automatically load symbols for all modules"
Start debugging C# code
In VS2010 C++ Project, select attach to process to attach the project to vs2017 exe; under select I chose both "managed" and "native"
The breakpoint of my c++ code showed as invalid since"no symbols have been loaded for this document"
I have been struggling with this problem for a long time. Any suggestion would be really appreciated!
I have been stump in this problem for a few hours now. I hope someone has had a similar problem to this.
We have developed a prototype .Net(C#) dll using VS2010, and would like to be able to call this dll in a both C# applications and VB6 application.
My question is:
Is it possible to debug a VB6 application that is calling a .Net dll? I get an error message "Automation Error The system cannot find the file specified"
The error message suggests that there is something missing for my VB6 app to find the .Net dll.
I am aware that if the VB6 application has been compiled, and the .exe has been created, the VB6 will successfully call the .Net dll functionality when using the .exe
However it is important that we can debug through our VB6 application. Unfortunately debugging does not allow you to step over the line of code instantiating the .Net DLL's class object. I can't seem to do this.
NOTE: I have looked around forums and MSDN documentation and I mostly find solution for calling a VB6 dll in .NET; which is unfortunately the opposite of what we need to do.
NOTE: I have already registered the compiled .Net(C#) assembly, and referenced it in the VB6 project.
I have however found these two pages, which seemed to be what we need, but its a solution for calling a .NET(c#) dll generated using VS2005. This doesnt seem to work when the .NET(C#) dll was generated using VS2010.
site1
site2
If someone could give any suggestions or direct me somewhere I can get one, that would be great.
Thanks
SOLUTION
Thanks to #HansPassant, I have found the solution.
To debug a VB6 project that contains a C# .NET assembly, you need to register the .NET dll through both "regasm" and "gacutil", then make sure to close and reopen the VB6 application before you start debugging.
This is not a problem, VB6 uses its own debugger that doesn't get in the way of any other debugger, including the managed one for C# code.
You start from your C# class library project, ensure it is selected as the start project. Project + Properties, Debug tab. Select the "Start external program" option and enter the path to the VB6 IDE. Typically c:\program files\microsoft visual studio\vb98\vb6.exe. Set a breakpoint on the method you want to debug.
Press F5 and the VB6 ide will start running. Load or create your vb6 project. Note how you can add the path to the .vbp project in the previous step so it will automatically load your project.
Start debugging your vb6 project as usual. As soon as it starts using your [ComVisible] C# class then your C# assembly gets loaded. And the breakpoint will hit when your vb6 code calls the method. Switch back and forth as needed. Note that you cannot single-step from vb6 to C# code, you have to set breakpoints to get the debugger to stop.
Ah, the wonders of using .NET from VB6 in a debuggable manner.
in the VB6 project compile options (reached using the Options button on the Make Project dialog window), choose the Compile to Native Code, No Optimization, and Create Symbolic Debug Info options. Then compile your VB6 project. These options allow proper VB6 binary-to-source mapping.
Go to the Configuration Properties...Debugging property page of your solution and change the Start Action to launch your VB6 executable.
In VS Solution Explorer, go to File...Add Existing Item and navigate to the folder containing the VB6 source code you want to debug. Double-click on the VB6 source code file you want to debug, and a source window should open in VS that allows you to set breakpoints in the VB6 source code.
Make sure that your .NET library has a public default constructor. This is essential.
Now also set any C# breakpoints that you need. Do not step into the .NET code - this doesn't work.
When you start debugging with VS, your VB6 and C# breakpoints should be hit normally.
One approach is to debug each individually:
Debugging the VB6 code can be done in the IDE after compiling the C# DLL and adding it as a reference to the VB6 project.
Debugging the DLL with the VB6 host is possible in Visual Studio by compiling the VB6 project and using it in the project properties as the executable to run.
In some cases this is simpler/quicker than setting up the environment to debug both simultaneously.
This approach will require having at least the framework of each working beforehand.
I work in a game engine called Unity3D whose scripting system runs on Mono. By default Unity uses a modified version of Mono to develop/compile script. I am in the process of setting up my Visual Studio to better work with Unity projects and its various gotchas with regards to .NET.
I am currently stuck trying to configure Visual Studio to handle compilation of my various assemblies. Unity uses a modified version of an old Mono compiler, and as such I cannot use the default csc.exe to build assemblies.
My ideal solution would be for Visual Studios's Build Solution option to process my projects with a compiler I point it to, perhaps through configuring the MSBuild (.csproj) file? Falling short of this is there another way I can build from within Visual Studio using Mono's mcs/gmcs compiler?
One approach would be to write an MSBuild/PSake script that you could run via a shortcut key from within VS. I've written a blog post about hooking a build script up via a shortcut key. Basically, you would write a batch file that executes the MSBuild script and assign a keyboard shortcut to it, say ALT-1. You would then hit ALT-1 instead of CTRL-SHIFT-B to compile the project.
I did a project where Unity was running on my Mac and ran Windows/VS2008 on Parallels. In my Visual Studio solution I referenced the appropriate Mono dlls instead of the normal .NET dlls (i.e. System, System.Xml, etc.) and used the typical .. I also wrote all my unit tests using the nUnit dlls provided with the Mono distribution. Since Unity is (or at least was) using just the .cs files, simply copying (via Post Build Script) them into my Unity project structure worked great. Unity would detect the change and update the scripts. This method was very effective, however I was using it about 2 years ago so I'm not sure if it still applies.
In addition it appears that someone went through the trouble of making a video on how to do this:
http://forum.unity3d.com/threads/120327-Video-Tutorial-How-to-use-Visual-Studio-for-all-your-Unity-development
I have created a visual c++ 6.0 dll project and using it from my c# code. Now i want to debug the dll but i am not able to do it.
I choose the following option to do it:
put the breaking point in my visual c++ project code.
build the dll and copy it into the directory of my c# project.
Now i build my c# project and dll works fine (method are calling perfectly).
Now i want to debug the dll.
I follow a blog and open the c++ project and choose the Attach to process from vc++.
but i am not able to find the running process of visual c# project, whereas it available at task manager process.
In my c# project solution i have two project i.e.
web service (i called the dll method at the time of accessing a url)
Another one is webform application which starts the web services.
Now please help me how should i debug my dll. I have followed so many blogs but all of them are focusing on Attaching process method which is not working in my condition. What should i do?
You'll need to enable unmanaged debugging, it is not turned on by default in either scenario because your main program is managed.
You do it in your C# project with Project > Properties > Debug tab > tick the "Enable unmanaged code debugging" checkbox.
You do it with Tools > Attach to Process by clicking the Select button. Choose the "Debug these code types" radio button and tick both Managed and Native. You may have to resort to only native if your process is 64-bit.
Set a breakpoint in the DLL's source code and be sure to write C# code that exercises the DLL function. If you still have trouble getting a breakpoint then use Debug > Windows > Modules and verify that you see the DLL in the module list. Get additional troubleshooting info by right-clicking it, select Symbol Load Information. Which shows a trace of where the debugger looked for the PDB file.
You can add C++ project to the your C# solution and add reference directly to the project (not dll), then you will not be needing to copy DLL. After that just start normal debugging (F5) of your C# project, and breakpoints will be working for C++ project too. This way will be very comfortable for debugging. I have tried such debugging and did not change any other settings.