Can't debug Outlook add-in project - c#

I have a problem in Outlook 2010 add-in project, After first debugging for the project I can't debug it one more, it show me the following warning :
The following module was built with optimizations enabled or without debug information:
{Path to 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.
and it didn't take any change I have made.

To debug, you need debug symbols and non-optimized code - make sure you have Debug symbols enabled for your build configuration, i.e. Define DEBUG constant checked and optimizations disabled, i.e. Optimize code unchecked.

Related

PostSharp - Seems like debug symbols are not updated

I have a Web Api (.net4.5) project with PostSharp(v3.1.52) added. When I try debug the source code, the single step (F10) doesn't jump to the next code line. It jumps to random lines below. If I put breakpoints on the lines it has skipped it says no symbols have been loaded.
I also cannot inspect some symbols - ie I get dreaded error "Cannot obtain value of the local variable or argument because it is not available at this instruction pointer, possibly because it has been optimized away."
This usually is a sign I'm not running in debug mode.
Things I have tried...
check the project is running in Debug mode - can confirm this by writing logs inside #if Debug.
Set SkipPostSharp = True
Uncheck "Optimize code" in the Project Build settings - FYI is I do this no debug symbols even load.
Installed lastest VS2017 updates (15.7.2)
Cleaned the solution
Restart machine
Last resort, I have changed .net versions and also tried updating PostSharp to later nuget version, alas no changes.
I'm not entirely sure that PostSharp is the issue, not ruling it out though.
Any ideas?

Symbols settings

When debugging the below following message appears in the immediate window. Can anyone explains to me easily what exactly does it mean and whether I should enable something related to this? Notice that I have already found some information on the internet but to be honest don't get it at all.
Use a debug build configuration or disable the debug option 'Enable Just My Code'.
Check the 'Symbols' settings under debugging options.Symbols for the module 'myapp.exe' were not loaded.
Use a debug build configuration or disable the debug option 'Enable Just My Code'.
Check the 'Symbols' settings under debugging options.
Sometimes, while you are debugging, you might want to look at only the code you have written and ignore other code, such as system calls. You can do this with Just My Code debugging. Just My Code hides non-user code so that it does not appear in the debugger windows. When you step, the debugger steps through any non-user code but does not stop in it.
Click here to read more about that topic in the documentation.

Visual Studio 2015: I can't debug and use breakpoints in Release mode

I have developed an UWP app that uses a lot of NuGet packages (MvvmLight, SQLite, ...) and other resources (Syncfusion controls).
I encounter a bug with the Store app, which is already published for tests, that is not present when I build the app in "Debug" mode.
So, I've tried to debug in "Release" mode, with the checked options "Compile with .NET Native tool chain" and "Optimize code". The build ends successfully, but I encounter an exception with a Syncfusion control (SfDataGrid) on the main page of the app. I would like use breakpoints to understand what happens, but they are deactivated as I build the app in "Release" mode.
If I build the app in "Debug" mode, with the same options checked ("Compile with .NET Native tool chain" and "Optimize code"), I don't encounter the same bug with the Syncfusion control, and the defined breakpoints are well keeped.
So I don't see how I could fix my problem:
if I create a new solution and built it in "Release" mode, the breakpoints are well keeped, and I can debug the code
if I build Syncfusion samples in "Release" mode, it's the same thing: the breakpoints are well keeped, and I can debug the code
I have compared the "build" parameters of the app and the other ones: they are the same
I have also looked at the "Just-in-Time" page, in the Visual Studio "options". I've got the following error: "Another debugger has registered itself as the Just-In-Time debugger. To repair, enable Just-In-Time debugging or run Visual Studio repair.". Ive tried to "repair" Visual Studio, but it's always the same thing...
Here is the "Options" settings:
And the result in solution, where breakpoints are disabled:
Would you have any explanation? How could I do to debug my app in "Release" mode?
[Edit 1]: add some details after further investigations
My app is based on a "template" like Template10, called Nentang. The structure of the project is the same, and they share a big part of references or NuGets packages.
But if I compare the build result of the "blank" Nentang and my solution, there are some differences that I don't understand:
as explained, on my app, the breakpoints and debug don't work in "Release" mode, and I can see that almost all modules don't have any "Symbol File":
=> only "ntdll.dll" and "KernelBase.dll" are linked to thier pdb file in a local directory: "C:\Users\myname\AppData\Local\Temp\SymbolCache"
on the "blank" Nentang app, the breakpoints and debug work well in "Release" mode, and I can see that almost all modules have a "Symbol File":
=> allmost half of the modules are linked to the same file in the "project" directory: "C:\Projects\Samples...\Nentang.UWP\bin\x64\Release\AppX\Nentang.UWP.pdb"
=> another quarter of the modules are linked to the same file of a "system" directory: "C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.NET.Native.Framework.1.3\1.3\x64\ret\Native\SharedLibrary.pdb"
=> the other modules are not linked to a Symbol File: it's the case of "ntdll.dll" and "KernelBase.dll"
How could I restore the "Symbol files" of my project?
I have also remarked a "strange" parameter in the properties of my solution, that is not present is the Nentang properties:
There is this parameter: "f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs"
What does it mean? Could it explain my problem?
Debugging optimized code is always a challenge - even more so with .NETNative. Here are a few things you could try:
Disable Just My Code
Suppress JIT Optimizations: This will not help for modules built with .NETNative toolchain. If the exception occurs in Release builds without .NETNative, then check the debugger option called "Suppress JIT optimization on module load (Managed Only)". As the name implies, this will cause the CLR to JIT compile code unoptimized, which will allow you to set breakpoints and inspect locals.
Look at the Output window for clues as to what went wrong. The exception message will be there and the preceding messages may help diagnose the cause.
Debug your application with Native debug engine. You can do this by checking the Native checkbox under the Debug tab of the project properties.
Last resort is to debug the assembly.

#If DEBUG is ignored (VB.net or C#)

I have several of these in my code which have been working fine so far:
#If DEBUG Then
... some code here
#End If
Now, i am noticing that, lately, the code inside the " #If DEBUG Then ... #End If"
gets execute also in "Release Mode".
This is strange and did not happen before. What could have happened so that
the #If DEBUG are now being ignored (they are ignored both in debug in the IDE or the final executable) ?
I have applied Clean, Rebuild, etc.: no luck. Thank you for any hints and help.
-Pam
Firstly, make sure you understand the difference between how you're running the code and how you're building it. Too many people equate "launching in a debugger" with "the debug version" and "launching not in a debugger" with "the release version". They're completely orthogonal - you can launch a release build in a debugger (typically with less information available) and you can launch a debug build not in a debugger. Apologies if you were already aware of this.
Now, assuming you really have changed the project configuration you're building to Release, you need to check the project properties for that specific configuration. I don't know what it looks like in VB, but in C# in the project properties, in the build tab, there will be a list of defined symbols - that is what affects whether #if DEBUG code is built or not. Perhaps someone has copied over the project configuration from Debug into Release?
EDIT: One way to check this at build time is:
#if DEBUG
#error This shouldn't happen
#endif
In a release build, that should build without error. In debug, it won't.
EDIT: Another option is that your overall solution configuration is now referring to the wrong project configuration types. I can't remember the exact menu name, but if you look around Project for Configuration Manager, you should be able to bring up a grid mapping "Project" and "Solution Configuration" to the project configuration to build.
C# Project ( Visual Studio )
go to: Project Properties -> Build(tab)
Select Configuration: Release
Uncheck "Define DEBUG constant"
Now select Configuration: Debug
Check "Define DEBUG constant"
In your code, you can now type the following ( DEBUG with uppercase )
#IF DEBUG
// Debugging code goes here
#ENDIF
Under Project Properties / Compile / Advanced Compile Options there is
a checkbox called "Define Debug Constant" that sets this.
Check out: http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_24658238.html
EDIT: Try this initializing with this:
#If CONFIG = "Debug" Then
#CONST DEBUG = true
#if CONFIG = "Release" Then
#CONST DEBUG = false
Did you, by any chance, tick the "Define DEBUG constant" for the Release configuration, while you were in the Project Properties / Build?
Also make sure you are not building the project-level Debug configuration within the solution-level Release configuration (see the Configuration Manager).
Also remember #if DEBUG must be in uppercase. e.g. #if debug won't work.
Had a similar problem where "DEBUG" was never true. Tried by doing an uncheck and check of the "Define DEBUG constant" checkbox and rebuilding everytime but that did not work.
My solution was to define "DEBUG" manually in the "Conditional compilation symbols" textbox for the Debug configuration. When rebuilding, Visual Studio 2019 automatically removed the DEBUG symbol from the textbox (because this indeed should not be there) and from then on it worked again. When i switched from Debug to Release the correct lines got greyed out.
This seems to be a possible bug in VS 2019 (16.4.5)?
undefine DEBUG and that will not execute that portion.
If you are using ASP.NET make sure about this line in Web.Config file:
<compilation debug="false" targetFramework="4.5">
So if debug="true" your project runs in DEBUG mode.
If you are using VB.NETFramework v4.5 then use like
If Debugger.IsAttached Then
'... some code here
End If

Is there any possibility to include *.pdb file into Release build to see error line number?

I made a project, all the settings are default.
When i run it in Debug mode (Build config = Debug) and face with exception - it dumps to my custom logging mechanism whith error line number, but when i run Release build - the same exception is logged without line number, only method throwing and call stack are logged.
Is there any possibility to enable detailed debug info in Release config (*.pdb files or smth.)?
On the Build tab (and when in the "Release" configuration), you can click Advanced... to change the Debug Info to "full", but note that this may make some compiler optimizations impossible.

Categories

Resources