473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C# optimized code prevents debugging

I have the simplified build ("show advanced build configurations"
turned off), so that pressing F5 runs in DEBUG mode with the
debugger. When an assertion fires, I find that I cannot 'watch' some
data, it explains that "Cannot evaluate expression because the code of
the current method is optimized". I know that I can go into Project-
>Properties->Build->"optimize code" and turn this off.
My question: WHY is the DEBUG build optimizing code? Shouldn't that
only occur for RELEASE builds? And, is my simplified build settings
("show advanced build configurations" turned off) causing this
"optimize code" to be set for both DEBUG and RELEASE, whereas maybe it
would only be set for RELEASE?

Zytan
Jul 24 '08 #1
7 2547
Zytan <zy**********@gmail.comwrote:
I have the simplified build ("show advanced build configurations"
turned off), so that pressing F5 runs in DEBUG mode with the
debugger. When an assertion fires, I find that I cannot 'watch' some
data, it explains that "Cannot evaluate expression because the code of
the current method is optimized". I know that I can go into Project-
Properties->Build->"optimize code" and turn this off.

My question: WHY is the DEBUG build optimizing code?
Because you've told it to, by the sounds of it. If you've got
optimisation turned on in the project properties (which it isn't by
default) then why would you expect it not to optimise?
Shouldn't that only occur for RELEASE builds? And, is my simplified
build settings ("show advanced build configurations" turned off)
causing this "optimize code" to be set for both DEBUG and RELEASE,
whereas maybe it would only be set for RELEASE?
Not sure what you mean - I haven't seen "simplified build settings"
before.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jul 24 '08 #2
... If you've got
optimisation turned on in the project properties (which it isn't by
default) then why would you expect it not to optimise?
I would expect this to be one of those properties that affects ONLY
the release build, not the debug build:

http://blogs.msdn.com/lukeh/archive/...17/482045.aspx
"Project Properties don’t allow you to choose which build
configuration they apply to. Instead, the setting you provide is
applied to either both or just Release depending on the setting."

I would have assumed "optimize code' would apply to JUST the release.
I mean, why would you want DEBUG code to be optimized? Ever?

Thanks for your reply, Jon.

Zytan
Jul 24 '08 #3
http://blogs.msdn.com/lukeh/archive/...17/482045.aspx
"Project Properties don’t allow you to choose which build
configuration they apply to. Instead, the setting you provide is
applied to either both or just Release depending on the setting."
(Note that this refers to the C# Express edition... please read the
whole article, it's interesting if you don't already know about it.)

Zytan
Jul 24 '08 #4
JS
I always assumed that this was because
System.Diagnostics.Debug.Assert() is optimized. I never suspected it
had anything to do with any build settings of your project. When I
hit an assertion, I just hit Shift-F11 to get out of the Assert()
method, and then I can look at values of properties.
Jul 24 '08 #5
Zytan <zy**********@gmail.comwrote:
... If you've got
optimisation turned on in the project properties (which it isn't by
default) then why would you expect it not to optimise?

I would expect this to be one of those properties that affects ONLY
the release build, not the debug build:

http://blogs.msdn.com/lukeh/archive/...17/482045.aspx
"Project Properties don=3Ft allow you to choose which build
configuration they apply to. Instead, the setting you provide is
applied to either both or just Release depending on the setting."
Interesting. It's often the case that making things simpler for some
people makes them more complicated (and less predictable) for others :(
I would have assumed "optimize code' would apply to JUST the release.
I mean, why would you want DEBUG code to be optimized? Ever?
Because "Debug" is just an arbitrary label, I believe. There's nothing
really magical about Debug and Release as build configurations, as far
as I know. You can create your own, call them what you want and tweak
them however you want.

Disallowing certainly combinations based on the name would be quite odd
IMO as well as presenting some UI difficulties.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jul 24 '08 #6
Interesting. It's often the case that making things simpler for some
people makes them more complicated (and less predictable) for others :(
Yes.
I would have assumed "optimize code' would apply to JUST the release.
I mean, why would you want DEBUG code to be optimized? Ever?

Because "Debug" is just an arbitrary label, I believe. There's nothing
really magical about Debug and Release as build configurations, as far
as I know. You can create your own, call them what you want and tweak
them however you want.
I understand. But, it appears that this 'simplified' project settings
for Express editions make clear decisions based on Release or Debug,
meaning that they are not just labels -- not in this context. The
settings specifically apply to one or both. It's too bad it doesn't
tell you which. :)

When I turn ON "show advanced build configurations", it shows
"optimize code" ON for Release and OFF for Debug, which is what I
expect (although, I may be the author of those settings).
Disallowing certainly combinations based on the name would be quite odd
IMO as well as presenting some UI difficulties.
Yes, but, as the article states... this is what they desired. The
point being: for the beginner who comes into C# Express who just wants
to build Debug and Release and not worry -- that's who it's for. And
I've grown to like it because it's simple, but I dislike it because it
does things like optimizing code for Debug when I didn't want it to.

Zytan
Jul 24 '08 #7
I always assumed that this was because
System.Diagnostics.Debug.Assert() is optimized. I never suspected it
had anything to do with any build settings of your project. When I
hit an assertion, I just hit Shift-F11 to get out of the Assert()
method, and then I can look at values of properties.
Nope, it's because the code is optimized by the compiler, and the
debugger doesn't know where the values are that you want to look at.
Run the same code with "optimize code", and you'll see everything you
want to see.

Zytan
Jul 24 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: SSG | last post by:
Hai All! I need the optimized code for finding the string length. i dont want to use strlen function......... can anyone know reply........ By S.S.G
8
by: Fuzzy | last post by:
I want to experiment with the JIT compiler's optimization of code, especially regarding inline compilation of small methods. What I have done is set the Build options for 'Optimize Code' to TRUE...
1
by: Johann Blake | last post by:
My ASP.NET application is written using C# script as well as C# code-behind. After setting a breakpoint in the script and running the application, I click from one page to the next but when I...
3
by: Mike | last post by:
In VB 6, you could change most code while your project was in Break mode. I am targeting the Pocket PC, and VB .NET 2003 is not allowing me to change code while debugging. Is this true for all VB...
10
by: Mike | last post by:
Is it still true that the managed C++ compiler will produce much better opimizations than the C# compiler, or have some of the more global/aggressive opimizations been rolled into the 2005...
2
by: JM | last post by:
Hi, I used to chage my code during debugging with Visual Studio 2003 (I just stopped the code using a break point and VS2003 allowed me to change the code, and continue debugging), but now with...
1
by: Tem | last post by:
Why can't I edit the source code while debugging in the 64bit edition of VS but can in 32 bit? Tem
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.