Built with optimizations enabled or without debug information - c#

I'm currently trying to find out why my InjectableAttributes never get to the filter part.
Therefor I linked in the source project directly so I could easily put breakpoints etc.
When I build however I get the following message:
The following module was built either with optimizations enabled or without debug information:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\[a bunch of randomly named directories]\assembly\[more random names]\MvcTurbine.Web.DLL]
To debug this module, change its project build configuration to Debug mode. To suppress this message, disable the 'Warn if no user code on launch' debugger option.
I checked the project's properties. It's configuration is set to "Active(Debug)" and the "Optimize code" check box is unchecked.
UPDATE
I checked again if I didn't by accident include the file rather then the project, but the references seem correct.
Just to be sure I also removed all existing bins so that all libraries are definitely rebuild somewhere, but to no avail.
UPDATE
In the advanced Build window the Debug output is set to Full and all options are identical to projects that are building debug info.
The config manager shows that the project is being built and has the exact same settings as all the other options.
UPDATE
In the Debug->Windows-Modules window the symbol status for the turbine library is PDB file does not match image I removed all corresponding pdb files on my entire system to make sure it gets re-generated, but to no avail.
To make sure I also searched for the dll on my entire system and removed them. Nothing.
What can be preventing VS from creating debug information?

I've just experienced the same problem this morning, using VS2010. I solved it by deleting all the build artefacts, e.g. executables, libraries, PDBs, etc. This was in \bin\Debug, \bin\Release, \obj\Debug, and \obj\Release (including sub-folders). Then I recompiled the debug configuration, and was back in business.

Check that debug info is being generated for the project. You can do this by opening the Build tab on the Project Properties page and clicking the "Advanced..." button. Check the "Debug Info" setting. See this MSDN article for an explanation of what each option means.
If that doesn't solve it, check that the MvcTurbine project is actually being built (Build -> Configuration Manager).

It sounds like you've referenced the MvcTurbine.Web.DLL file rather than the MvcTurbine project. Try removing the reference and re-adding it as a project reference.
Update Are you sure the DLL isn't coming from the GAC? Do Debug->Windows->Modules when the app is running and check the Path column.

Related

Visual Studio PDB file for project in same solution not generating

I have the main project referencing the Pencil.Gaming library which is compiled as a DLL. The DLL however does not generate a PDB file or is for some other reason not debuggable, so breakpoints are never hit.
How would I make Visual Studio generate that file properly? I searched alot on google and here before but didn't seem to find a proper answer.
The DLL project is added as reference if that helps solving it.
To fix this you have to open the project properties of the project you want to enable debug file creation on. Then go to Build and click the "Advanced..." button at the bottom.
Now set the debug information dropdown to "full" (or whatever you want it to be).
Screenshot of where to find it in detail
"Debuginformationen" is the field you want to change.

How can I suppress the generation of 'trash' from nuget packages?

In a current project, I use lots of nuget packages for all kinds of purposes (Nancy, Unity, Razor..) and they all generate a lot of noise in the application output directory, even on release configuration. How can I prevent those from doing so?
*.pdb debug databases
*.xml documentation files
*.unnecessary locale resources (I have like 20 folders in my output directory for every goddarn langauge..)
Check configuration manager for your "release" build and see if all your projects are actually set to release. If they are, check each projects properties, on the build tab see what constants are defined (not sure if this would affect things or not), click the advanced button, see what the debug info is there.
If you really want to get rid of those things (after all, they are there for a reason) I'd suggest defining post build events in your project properties to have them deleted by Visual Studio once your project has been built successfully.
Make sure to use the appropriate macros to target the correct directories. Also, uncheck the creation of DEBUG and TRACE constants and XML documentation to suppress the creation of *.pdb and *.xml files for your own project.
MSDN on build events

Symbol file not loading for debugging custom project in Visual Studio 2012

I have a large solution in Visual Studio 2012 which consists of executables and class library projects.
When debugging the application the breakpoints in one particular class library project are not being hit.
I looked at the Debug> Windows> Modules window to check the status of the symbols for that project and it says "Cannot find or open the PDB file".
It also says "No" under the "User Code" column.
I notice that there are a few other of the custom projects in the solution that are showing "No" in that column and their symbols are also failing to load. Anything with a "Yes" under "User code" seems to have had it's pdb loaded no problem. But I'm not sure if this is relevant.
I have used dumpbin /headers on the dll and the path for the pdb file is present and correct.
The module is definitely not in the exclude list for the symbol loading.
I have also tried right clicking on the entry in the modules window, selecting "Load symbols" and navigating to the path given in the dll header. When I select the pdb it says "A matching symbol file was not found in this folder".
I get this after I have deleted these folders and files, cleaned the solution, closed it and rebuilt the whole thing.
The pdb was definitely built at the same time as the dll in question.
So clearly the problem is the "cannot open the pdb" portion of the error message.
I have tried this on 2 computers and both are exhibiting the same behaviour.
Can anyone offer any suggestions on where to go from here, and perhaps why on earth the built pdb corresponding to the dll won't load for it?
I tried a few tools to check if the pdb and the dll actually matched, and using chkmatch I could see that the GUIDs in the dll being run and the pdb in the obj folder didn't match.
So it turns out that although the dll and pdb in the project's obj folder are a match, the dll that was actually getting copied to the application's destination folder by a post-build event was the old dll from the previous build.
The post-build event was running before that particular project had built, or at least finished building, and was copying in the existing dll from the bin which was subsequently overwritten by the continuing build.
I have resolved the problem by editing the project dependencies for the solution and ensuring that the project with the post-build event is dependent on the project that wasn't loading, and now the pdb loads during debug.
I simply deleted bin and obj folder from the startup project folder and rebuild the solution.
For me I just deleted the project from IIS and created it again and it works fine
For me it helped to use chkmatch tool and then just close and open visual studio, make clean and rebuild. Now my pdb gets also loaded. You can make sure it does, as Nanhydrin pointed out, from Debug -> Windows -> Modules - this view is only accessible during debugging.
I found that the project I was receiving the message about, was being optimized when built.
I went into the projects properties, Compile Tab, Advanced Compile Options... and unchecked the Enable Optimizations checkbox
In my case older version of referenced dll was in my GAC. Cleared it out, and it worked.
In my case there was a check mark on Enable Just My Code in Tools>>Options>>Debugging>>General.
I unchecked it and it worked.
Example Image
Reminder: Put the project into "Debug" configuration... for those like me who forget and feel silly.
I just had this issue and thought I would put my fix here, as it my help others (maybe even myself again?!) in the future...
Make sure that when you are attaching to the process on the remote server, that the "Attach to" is set to
Automatically determine the type of code to debug
To do this, When the server qualifier has been provided and a list of processes is visible, click the "Select" button next to the "Attach to" input.
Then, select "Automatically determine the type of code to debug" and OK out of the screen, then attach.
This fixed the issue for me, at least.
Deleted the project from solution and added it again to the solution worked for me. :)
Bit late to the party here - just in case this is helpful.
We have a couple of separate websites (in different solutions in Visual Studio). On initial load of one of the sites, we were making a call to the other site which would return an image.
Both of these sites referenced a common DLL, but while working on one site, had not realised that the other site had been left in a 'Release' build - after the site loaded, the offending DLL was rebuilt, but without symbols.
Kudos to Nanhydrin for both mentioning the modules debug window (very helpful) and for putting me on the right track with the post build event.
Answer from another thread that worked for me: https://stackoverflow.com/a/28476665/5969306
- In Visual Studio: Project Properties -> Build -> Advanced button -> Debug info drop-down and make sure the value is not “none”.
I had a line like this in my debug window:
Symbols for the module 'MyModule.dll' were not loaded.
I removed the 'Optimize code' option in Project properties -> Build. And the error disappeared.
This issue may be due to wrong reference of dlls used in project.
Delete obj and bin folders in current project and build project again.
Check for permission to ASP.NET Temporary folder:
"c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files"
User of application pool has to have the rights to subfolder with ASP.NET files, something like:
root\60039743\c28e12ee
Check options from this answer: https://stackoverflow.com/a/38377530/6911991
Click Advanced and check that Debugging Information is set to FULL
Check Run Configuration in all projects in the solution
I had this issue , tried all the other solutions (it took 2 days !! I'm crying... !TWO DAYS!) But finally I realized that my file was registered in GAC, I removed it and the problem was resolved.
At the command prompt, type the following command:
gacutil –u <assembly name>
How to: Remove an Assembly from the Global Assembly Cache
Please check the dependency of your dll, if you added to the solution, this can cause failure in loading symbols.
I resolved this issue by disabling 'Use Managed Compatibility Mode' in the Debug->Options menu:

How do I remedy "The breakpoint will not currently be hit. No symbols have been loaded for this document." warning?

A C# desktop application (on the Visual Studio Express edition) worked, but then it didn't work 5 seconds later.
I tried the following:
Ensure debug configuration, debug flag, and full debug information are set on all assemblies.
Delete all bin and obj folders and all DLL files related to the project from my entire machine.
Recreate projects causing the problem from scratch.
Reboot.
I have two Windows Forms projects in the solution. One of them loads the debug information, one doesn't. They both refer to the assembly I'm trying to get debug information on in exactly the same way in the project file. Any ideas?
I want to add here, mostly for myself when I come back to review this question, that symbols are not loaded until the assembly is loaded, and the assembly is not loaded until it is needed. If the breakpoint is in a library that is only used in one function in your main assembly, the symbols will not be loaded (and it will show the breakpoint as not being hit) until that function is called.
Start debugging, as soon as you've arrived at a breakpoint or used Debug > Break All, use Debug > Windows > Modules. You'll see a list of all the assemblies that are loaded into the process. Locate the one you want to get debug info for. Right-click it and select Symbol Load Information. You'll get a dialog that lists all the directories where it looked for the .pdb file for the assembly. Verify that list against the actual .pdb location. Make sure it doesn't find an old one.
In normal projects, the assembly and its .pdb file should always have been copied by the IDE into the same folder as your .exe, i.e. the bin\Debug folder of your project. Make sure you remove one from the GAC if you've been playing with it.
Check to make sure that you are not in release but in Debug.
When in debug:
First try rebuilding your project by right mouse click the project > Rebuild
If that doesn't work, try a clean of the project (right mouse click on the project > clean)
If that didn't work check this:
Right mouse click your project
Select [Properties]
Select the [Build] tab
Make sure [Define DEBUG constant] and [Define TRACE constant] are checked
Make sure [Optimize Code] is unchecked
Click the [Advanced] button at the bottom of the Build tabpage
Make sure that [Debug Info:] is set to [full]
Click [OK] and rebuild the project ;-)
(step 7 generates the .pdb files, these are the debugging symbols)
Uncheck the "Enable Just My Code" option in the
Tools/Options/Debugging/General
Just something simple to try - you may have tried it already.
Right click the Solution in solution explorer, click "clean solution", this deletes all the compiled and temporary files associated with a solution.
Do a rebuild of the solution and try to debug again.
I've also had troubles with breakpoints multiple projects in a solution - some compiled as x86, some as x64.
The selected answer led me to fix my problem. But I need to do a few things more:
Even with "Debug" selected in the dropdown:
And in the project Properties > Build:
The Visual Studio was not loading symbols to a specific project. So in that dropdown I select "Configuration Manager" and saw that the settings to my web project was incorrect:
Then I set that to "Debug" and it started to generate the .pdb file.
BUT I need to manually copy the PDB and DLL and put in the folder that VS was looking (here is where the selected answer helped me):
Sometimes, even though it gives you this error, the Breakpoint still gets hit, so just ignore the error.
This happens fairly often in the Views of an MVC web app, i.e. .cshtml.
I was able to fix the error by simply setting the option in the 'Attach to Process' to 'Automatically determine the type of code to debug' option as shown in the attached screenshot.
Simply follow the steps below:
Go to Debug from the menu bar
Click on Attach to Process
Near the Attach to option, click on the Select button
The Select Code Type window will appear
Now select the option Automatically determine the type of code to debug and click the OK button.
Debug > Windows > Modules to see what modules were being loaded put me in the right direction.
In my case IIS Express seemed to be loading a different DLL from the temporary ASP.NET files.
The solution?
Browse to C:\Users\<YOUR USER>\AppData\Local\Temp\Temporary ASP.NET Files\vs
Delete everything in this directory!
Check if your .pbd file is missing in your bin/Debug folder. If it is then go to "Properties" of your project, selected "Build" and then "Advanced" at the bottom. Choose "full" under "Debug info" in the new window that appeared. This was my issue and solved it for me.
In my case "Optimize Code" was checked in my project properties. This caused VS to see my assembly as "not my code", and in turn, it did not load symbols for it.
The solution was to uncheck this.
Try running visual studio as an administrator within windows.
You need to enable "Generate debug info" in compiler settings
I tried everything mentioned above, but nothing worked.
[Clean solution, and check for PDB files etc.]
Even publishing the same solution did not resolve the issue.
Then I went to back to what I usually do to resolve (fool this stubborn Visual Studio)
All I did was to make a deliberate change in code and publish the solution.
Then I reverted the change and published again.
Voila [PDB files rid of evil spirits].. Not a smart resolution, but this did work.. :-|
We found the cause of our problem. This code was using the "CodeBehind" attribute in the Page directive of the .aspx file instead of the "CodeFile" attribute (ASP.NET 2.0 and beyond). After days of desperation, a simple search and replace solved the problem.
Option "Start debugging, Debug + Windows + Modules" does not exist in Microsoft Visual Studio Express 2013 edition.
Unchecking "Use Managed Compatibility Mode" in Tools Options Debugging fixes this.
Webapplications (IIS Express) only:
Rightclick IIS Express Tray and close the IIS.
Clean Solution
Clean solution and Rebuild
Check the configuration is set to Debug
Make sure that the PDB file is in the Debug folder it self
From Debug menu click Enable All Break points
Make sure you're in Debug and not is release by choosing debug in the dropdown menu like you can see in the picture below.
Then, try cleaning your project by clicking the right button in your mouse on the solution in the solution explorer window and choosing Clean solution.
Then rebuild your solution by clicking the right button in your mouse on the solution in the solution explorer window and choose Rebuild solution
Check are the following two setting the same in Visual Studio:
Right click test project, go to Properties, Build tab, and look at Platform target
Mine are all set to "Any CPU" so x64
On the Main Menu bar, go to Test, Test Settings, Default Processor Architecture
Mine was set to X86
Changing this to X64 to match above setting made the built in Visual Studio menu “Debug Test(s)” work and hit breakpoints that were previously ignored with the message “The breakpoint will not currently be hit. No symbols have been loaded for this document”.
Update:
For Visual Studio 2019 the menus have been moved around a bit:
I also had the same issue what I rebuild the whole solution (including refereced projects) in x86( or x64)
Even though I set all of my projects to x86 from Configuration Manager (Build->ConfigManager) some of my projects were not set to x86.
So Just to make sure right click on the project and follow
project -> properties -> Debug Tab, verify Configuration and Platform.
The .dll where I want to stop debugger and the associated .pdb files where copied near the .exe file. Those files had an older date so I thought they weren't updated in the runtime. I manually deleted them, Visual Studio create another pair AND put this new pair near the .exe. Now the breakpoint works!
Maybe Visual Studio cannot copy and REPLACE existing files (.dll and .pdb) near the .exe since there are another there. So if I deleted manually then VS could create new one near .exe.
I think that the root cause of the problem is that the Visual Studio use another file in runtime, no the file from the project, with the stop.
Instead of doing all these things just Close and reopen
Project Properties (then select your build config) > Build Tab > Advanced... > Debug Info (dropdown)
Set to 'all' or 'pdb-only' then rebuild
This took me a while tried other options above and for some strange reason debugging stopped working.
Tool -> Options -> Debugging -> General -> (untick) "Require source files to exactly match the original version" option
I was integrating a C# application with a static library using VS10 - which I'm new to. I wrote a managed code dll to interface them. I could set breakpoints everywhere but the static lib. I got the message described above - no symbols have been loaded for this document. I tried many of the suggestions above. I could see that the symbols weren't being loaded. I finally noticed a check box Configuration Debug, Enable unmanaged code debugging. That allowed me to set breakpoints in the static lib functions.
In my case, I was compiling a class library (DLL). No modules seem to be loaded in Debug -> Modules, so I couldn't even load the symbols manually.
My solution was to add this line to my code:
System.Diagnostics.Debugger.Launch();
Once this code is reached, an exception is triggered and .NET Framework shows a dialog box asking which Visual Studio (i.e. new instance of VS 2008, new instance of VS 2013, etc) you want to use to debug the program. You can choose the existing instance of VS with your project loaded. This will attach the process to your VS session and load all symbols, and now you can debug your project.
Of course, the compilation has to be done using the Debug configuration, not Release.
For an ASP.Net application, check the properties of the site, ASP.NET tab. Ensure that the correct ASP.NET version is selected.
I think the source if this error is, the debug symbols have a hard time surfacing to the solution after building for release.
I tried all the other answers -- generally, regenerating .pdb symbols or checking their location, cleaning and rebuilding project, ensuring active configuration is not Release etc.
What eventually worked for me is right-clicking on the project in solution explorer > Debug > Start new instance.
After trying a bunch of these, the thing that ultimately worked for me was this:
In Debug > Options > General, uncheck Enable Edit and Continue.
this happened to me after copy paste another webservice asmx file into an existing webservice, resulting in the same error when trying to debug the recently added service, to be able to debug I had to start without debug, then attach to the process. its weird but its the only way i found to be able to debug.

Breakpoint not hooked up when debugging in VS.Net 2005

Been running into this problem lately... When debugging an app in VS.Net 2005, breakpoints are not connected. Error indicates that the compiled code is not the same as the running version and therefore there's a mismatch that causes the breakpoint to be disconnected.
Cleaned solution of all bin file and re-compile doesn't help. Not just happening on a single box or person either.
Added Note:
This solution is in TFS for Source Control. If I delete my local TFS repository and get it from source control from scratch, SOMETIMES the problem goes away. I've also tried un-installing and re-installed Visual Studio. That also SOMETIMES helps. That fact that both of those work some of the time indicates that the problem isn't caused by either directly.
Maybe this suggestion might help:
While debugging in Visual Studio, click on Debug > Windows > Modules. The IDE will dock a Modules window, showing all the modules that have been loaded for your project.
Look for your project's DLL, and check the Symbol Status for it.
If it says Symbols Loaded, then you're golden. If it says something like Cannot find or open the PDB file, right-click on your module, select Load Symbols, and browse to the path of your PDB.
I've found that it's sometimes necessary to:
stop the debugger
close the IDE
close the hosting application
nuke the obj and bin folders
restart the IDE
rebuild the project
go through the Modules window again
Once you browse to the location of your PDB file, the Symbol Status should change to Symbols Loaded, and you should now be able to set and catch a breakpoint at your line in code.
Source: The breakpoint will not currently be hit. No symbols have been loaded for this document.
http://dpotter.net/Technical/2009/05/upgrading-to-ie8-breaks-debugging-with-visual-studio-2005/
In Options -> Debugging you can uncheck "require source files to exactly match the original version", which may help.
Is the build configuration set to Release?
Do you have a reference to an external DLL where the breakpoint is set?
Are you creating a DLL project that is consumed by an external executable? Are you using .NET or COM?
If you are using the COM Interop with .NET, the DLL versions can sometimes be a problem when the executable loads the DLL. For instance, if your daily build cranks out an incrementing build number but your debug DLL has a smaller build number, the executable won't load the debug DLL. To fix this, you will need to scan the HKEY_CLASSES_ROOT\CLSID directory in your registry for the GUID/CLSID of your .NET/COM component. Under InProc32, delete entries with a higher version number than your debug DLL.
Again, the above only applies to .NET + COM Interop DLLs.
I've had a similar problem in the past.
It was solved by closing Visual Studio and deleting the temporary ASP.NET generated assembly files for the project under "C:\WINDOWS\Microsoft.NET\Framework{framework version}\Temporary ASP.NET Files", re-opening the project.
Read the post here and the comments to resolve it.
AviewAnew - had already done that at the request of the MS tech person. It didn't help to uncheck require source file to match version.
Mike L - configuration is set to DEBUG and there are now external DLL. Using all local projects except framework references.
Are you sure the .pdb files are in the same folder as the executable you are running? Make sure the last modified date of both files match, and that VS is attached to that exe (and no other).
Do you have a post build step that touches your binaries in any way? If so, this can confuse the debugger and make it look like your symbols don't match your exe/dll because of the incorrect size/timestamp.
In the past I have sometimes found that switching off compiler optimisations can solve 'missing' breakpoints, as the optimiser had determined (correctly) that the code was not being called, and removed them from the compiled versions.
This does sound like a different issue, but it might be worth making sure that optimisation is switched off in Debug mode. [Project / Properties, Build settings tab]
Sure there are no Debug attributes on the code that prevent code from being debugged, such as DebuggerHidden or DebuggerStepThrough, at any point of the application?
Can you step through your code up to the line of the breakpoint instead of running and waiting for it to hit? Can you step through code at all?

Categories