473,756 Members | 3,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2566
Zytan <zy**********@g mail.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.co m>
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.Diagnost ics.Debug.Asser t() 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**********@g mail.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.co m>
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.Diagnost ics.Debug.Asser t() 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
3707
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
4608
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 and set 'Generate debugging information' to TRUE. I run the compiled application from Windows Explorer, crank up Visual Studio .NET, and attach to the running application with Tools -> Debug Processes... Since I generated debugging information...
1
2147
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 get to the page where the breakpoint is, the code doesn't break in the IDE at the breakpoint. The breakpoint is in a Page_Load section. All pages in my app are in the same directory and use relative linking to move from one page to the next. No...
3
1938
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 .NET projects or just for the Pocket PC?
10
2146
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 compiler? Are simple common sub-expressions and loop invariants optimized out in the current optimizer? thanks, m
2
3109
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 Visual Studio 2005 I am not able to do it. Can anyone tell me how I need to configure VS2005 so it allow me to change code during debugging?
1
1310
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
9273
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.