.NET - How to debug a DLL? - asp.net

I need to debug a class library project that is provided to the main project (an ASP.NET website) as a DLL. For example, I need to put some breakpoints in order to check what's happening during the execution.
I tried How to: Debug from a DLL Project, unfortunately it didn't work...
How can I do it?
PS: I have the source code!

If you have the source code, and the .pdb files in your BIN directory, then you can debug through that code. However, You will need to enable external code debugging in Visual Studio.
You need to uncheck the "Enable Just My Code" option: menu Tools --> Options --> Debugging --> Enable Just My Code
NOTE: This will only work for .NET assemblies.

Debugging DLLs in Visual Studio (see #2 in the list) may be what you're looking for (full disclosure: Yes, this is my personal web site).
With method #1, you can't watch variables.
With method #2, step #2, if you can't open the project in the same Visual Studio instance, you can run the binary of the project (that is, run it outside of Visual Studio, but make sure you run the debug version.) and attach the Visual Studio debugger to it (menu Debug -> Attach to Process).
Here are the steps for method #2 so no one has to follow the link:
Attaching a using process to the DLL project. This involved hooking the Visual Studio debugger into a running process.
Open the DLL project in Visual Studio.
Run an application that uses the DLL. This
application can't be run from
another instance of Visual Studio since the
process will already have a debugger
attached to it.
From here you can add breakpoints and step through
the DLL code loaded in Visual Studio (although
the breakpoint will appear disabled
the same as in method 1).

When you build the class library project, the .pdb file is created in the Debug or Release folder of that class library. These two file are referred to by the ASP.NET project when you right click and select the option "Add a Reference" and point to the DLL file of the class library project.

Related

.NET Core 31 - Single EXE - The application to execute does not exist

Converted an old .NET Framework project to .NET Core 3.1 yesterday. The application runs fine on my own machine and debugs correctly.
I have put both the following into my .vbproj/.csproj
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win81-x64</RuntimeIdentifier>
However when I move the .EXE to a remote machine and attempt to run said EXE on that remote machine I get told that the DLL (for the project in question) does not exists.
I moved the .dll to the same directory that the exe is in (not ideal) and get the following error instead
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
I used to use Costura.Fody to create a single file exe without any issues in .NET Framework, I was under the impression the above would do the same for the .NET Core packages.
Can someone point me in the right direction please.
For anyone else that may find this question and find it useless.
I was 'Building' the project instead of 'Publishing' the project, this in-turn wasn't creating the self-contained exe properly.
Don't be a donut like me.
In Visual Studio 2019, go to Build > Publish MyApp. This will open a tab in the editor area. Click on Show all settings to open the Profile settings dialog. Then click on File publish options and check Produce single file.

error when deployed to azure

When i Publish my project i m getting this error:
error CS0009: Metadata file
'D:\home\site\approot\packages\Microsoft.ApplicationInsights\1.1.1-beta\lib\net45\Microsoft.ApplicationInsights.dll'
could not be opened -- Invalid COR20 header signature.
(I m using asp.net core 1)
Did Someone knows or has experienced the same problem?
Thanks
This problem can occur when you have added a third-party DLL to your application and have not properly added it to your compiler’s project file or references list.
If that's the case this might work:
Open your project in Visual Studio .NET. Make sure the DLL exists and has been properly added to the reference list. If you are using VBC or CSC to compile your project, check your application’s CompileApplication.rsp file to make sure the DLL is in the /references list like the other DLLs.
Your DLL may not be compatible with .NET or with .NET’s 32-bit mode. Ensure that your DLL is .NET compatible.
If your project still won’t compile properly, try switching your application’s compiler selection in Iron Speed Designer’s Application Wizard from 'vbc.exe' or ‘csc.exe’ to Visual Studio .NET or vice versa. Using Visual Studio .NET will take longer to build than .NET’s VBC or CSC built-in compilers, but Visual Studio .NET will resolve all of the references properly without having to change your application’s CompileApplication.rsp file.

Visual studio 2010 dialog halts automated build

I am working on a project with a build that is automated using NAnt. The automated build includes NAnt tasks to clean the machine, including deleting and re-creating the virtual directory, clearing out VSWebCache, etc. Once the machine is reset, it attempts to compile the site with this:
<exec program="${visualstudio.install.dir}\devenv.com" commandline="SolutionFile.sln" failonerror="true"/>
The problem is that the automated build locks up at this point.
If I open the .sln file interactively, the first thing that happens is Visual Studio prompts me with a dialog box. I suspect this dialog box is "opening" (invisibly) when I run the NAnt script and I can't click on it to proceed.
The dialog message is:
Microsoft Visual Studio
The web (URL) is currently configured for use with ASP.NET 1.1. Web project (name) is targeting ASP.NET 4.0; if not configured some features may make incorrect assumptions, and pages designed with the tool may not render correctly.
Would you like the site to be configured for use with ASP.NET 4.0?
I do in fact have 3 different versions of .NET on my machine-- I work on multiple projects. I can't configure the site ahead of time because the build script will blow away my configuration anyway. I guess what I need is either an automated way to accept the dialog (as if I clicked the YES button) or a NAnt task that will automatically set up the vdir to be an ASP.NET 4.0 application.
I do have free reign to modify the build script as I see fit, but I cannot simply remove the portion that resets the machine-- our build box is shared with other projects and we have to reset everything to a known good state before running our compile.
Use MSBUILD directly, don't use devenv. It's the full IDE, and all you need is to build.

Problems with 'Publish Web Site' on Visual Studio 2010

Recently I've upgraded from Visual Studio 2008 to Visual Studio 2010, however I'm having various problems when uploading my compiled web site to the live area. I'm doing exactly the same as I would have done with Visual Studio 2008, however, now I receive errors such as:
{filename}.aspx is not a pre-compiled file
masterpage.master does not exist
All these errors don't make sense. Has anyone encountered these problems before, and was a solution ever found?
Try run the Clean Solution command from the Build menu on your solution.
Try diagnosing by publishing to a brand new IIS location. Perhaps there are files from your VS2008 build that aren't being overwritten by your VS2010 build.
Are all the files present in the bin directory as you'd expect?
Is there an PrecompiledAppConfig.config file in the root?
You can run the Clean command by selecting Build -> Batch Build. You will see the options Build, Rebuild, and Clean in the dialog box.
The web site does not have to be created in IIS in order to use the Batch Build dialog.
Hope this helps,
Rick
you probably have not created an application or virtual directory on your server.
use IIS Manager to create it

Is There a Visual Studio 2005 ASP.NET debug and release build

Is there a "debug" and "release" build in VS 2005? If so, how do I switch between the two?
Saif:
Are you working on an ASP.NET web site project?
If so, Visual Studio delegates the build step to the ASP.NET runtime, and the ASP.NET runtime picks up debug versus release in the web.config .
I have a post on the topic that will help: Debug and Release Builds in ASP.NET 2.0
Note that a couple things have changed since that time. Namely, MSFT released two add-ins for VS 2005 - one to add real web application projects that have debug and release settings (for the code-behind and loose c# files), and they also released web deployment projects, which can use the asp.net command line compiler. Web App projects became a part of VS2005 in SP1, too.
Use the Configuration Manager. Right-click on your solution in the Solution Explorer, select "Configuration Manager...", and change the active solution configuration.
You can change your project's behavior when in debug or release mode. Bring up your project properties pane, select the appropriate configuration from the dropdowns at top, and change the settings as appropriate. Notice that some changes are made by default for you. For instance, release builds by default are set to optimize code, and debug builds are not.
In the ASP.NET web.config file there is a debug="true" attribute. The first time you run the web application Visual Studio will ask you if you want to turn on debugging, selecting yes will cause Visual Studio to edit the config file for you.
Just remember to make sure you change that back to false for your release builds. For more info click here.
The quick way is to right click on the toolbars and turn on the standard toobar. Then you can quickly change between build targets by choosing the one you want from the solutions configuration drop down.
If you want to change what those configurations do, then follow what Michael Petrotta said in his answer.

Resources