Setting up VS 2013 to debug a DLL - c#

I have a C# solution with about 10 projects in it. It is a standard Windows Form application.
I have DLL in a separate directory that compiles fine and work so long as I move the DLL file into the executable directory of the main program.
Now I would like to add some functions to the DLL and debug it.
I have attempted to follow the MS help for How to debug from a DLL project but it is full of errors and cannot be used (3. where or what is the 'Project Property Pages window in the Configuration drop-down' for example).
http://msdn.microsoft.com/en-us/library/605a12zt.aspx
Is there a better reference for a first time user attempting to set breakpoints in a DLL?

I found the answer.
Ignore MS help (it is not)
Start a project with only the DLL in it
Add a project to that solution that calls the DLL
Make that new project the one that starts when you hit run
Its that simple.

Related

WPF ClickOnce missed references

I have a WPF app that works with local SQLite and Entity Framework Core. I want to distribute my app using ClickOnce.
Everything works fine when I run it using Visual Studio 2017. But app had a crash on a start when I used ClickOnce. The crash was so early so I couldn't even log the exception. After some time I found that in publish folder some dlls were missed. For example System.Runtime. All references are NuGet packages. Then I found that despite of I have a reference to the dlls in my project ClickOnce application files list doesn't contains it.
The only solution I have found for now is to add missed dlls as files in root of my project and set build action to Content. In ClickOnce application file dialog I set publish status to Include.
It works now but it looks like not the best way to do it. The question is why they are missed in the first place. More likely I missed something or I am not understand the root of the problem.
UPD:
You can find an example code here.
It works from Visual Studio but crashes on a start when you try to install it as ClickOnce application.
UPD: The problem was fixed in Visual Studio Professional version 15.6.1
There are two ways solving solve this.
At first, you have to go Properties → Publish → Application Files, and at this place, make your DLL files include in your project
But if it does not work, go to References and make the DLL file CopyLocal = False. You add a DLL file like Existing Item in your project and make them Copy Always.
It will work correctly.
But for your sample I watch this and I solved it. Look at this image:
You have four DLL files. You need do this for them:
System.Diagnostics.Tracing.dll
System.Reflection.dll
System.Runtime.dll
System.Runtime.Extensions.dll
At first go to your reference and make them Copy Local False:
Then go to the path of each DLL file and add them like Existing Item, and then make all of them Copy To Output Directory CopyAlways
Then Publish it and run it like in this picture. I run it from publish file and it works.
Even if you set the dll to copy local, the dll will not get copied over unless you actually use the dll in your code. You might try adding System.Runtime in your code somewhere like this maybe?
var dummytest = System.Runtime.GCSettings.IsServerGC;
Based on Issue 9 on https://blogs.msdn.microsoft.com/bclteam/p/asynctargetingpackkb/ I was able to do the following:
Symptom
ClickOnce applications targeting .NET Framework 4.0 that reference the Microsoft.Bcl or Microsoft.Bcl.Async packages may experience a TypeLoadException or other errors after being installed.
Resolution
This occurs because ClickOnce fails to deploy certain required assemblies. As a workaround, do the following:
Right-click on the project and choose Add Existing Item
Browse to the folder where the System.Runtime.dll lives
In the File name text box paste in the path of the file
Click the down-arrow next to the Add button and choose Add as Link
In Solution Explorer, holding CTRL select System.Runtime.dll
Right-click the selection, choose Properties and change Copy to Output Directory to Copy always
Republish

Create a standalone .exe file

I have a console application built in visual studio 2010.
When I actually build the project I am getting .exe file under \bin\Debug\MyProj.exe.
When I Paste and run this .exe from other location it is expecting other files too.
Any thoughts how can I make this as Stand alone exe file.
There should be other DLL's in the Debug library. You need those to run your exe.
If there are no DLL's there, make sure you set the 'Copy local' property of the required references to True, and build again.
If you want to make a standalone program, you should create a new Setup project in your solution. Include the Primary Output from your application project, and the setup should include the required DLL's automatically. Once you build the setup project, you can install your application as a standalone software.
You usually distribute application with bunch of DLLs, that's nothing bad.
But if you really want to make it a single exe, you can look here - same question is answered Embed .net dll in c# .exe . (Valid if your DLLs are also .Net assemblies)
Edit: If you need to easily distribute app to not-very-computer-friendly users, consider also trying ClickOnce. It's roughly something like Java Web start - only disadvantage is that you can't get "Windows Logo" certificate from Microsoft for projects distributed that way.
I don't have Visual Studio 2010 to experiment with, but in Visual Studio 2019 this worked:
Project Properties->Configuration Properties->Advanced->Use of MFC->Use MFC in a Static Library

Debugging VB6 project that calls a .Net(C#) dll

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.

How to debug the c++ dll from c# project?

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.

Why does my command line application error out on remote assembly when ran outside Visual Studio?

I have a very simple command line .net application. I have reference to a .dll assembly and everything works just great when I run the program inside Visual Studio. However when I try to double click the .exe file or run it manually via DOS or something it error out saying it doesn't have access or can't find my assembly reference.
What am I now understanding about this situation? Is it permission related or maybe I have to link the assembly reference in another way? I can't find anything on web related to this one.
Try copying the dll to the same folder as the exe if it is not already there.
If the dll is being built in visual studio as part of the same project then make sure that both assemblies are being compiled (build all).
When VS runs an application directly it creates a different version of the application and not the one you would release. You'll notice yourapp.vshost.exe thats visual studio's one and not the one you should run.

Categories

Resources