CodeBehind vs. CodeFile and the 'does not exist in the current context' Error

I find myself spending more time in .NET code lately.  While I was verifying my understanding of one of the other attributes of the @Page directive under the ASP.NET 2.0 (Visual Studio 2005) release, I stumbled across the following note regarding the CodeBehind attribute:

This attribute is included for compatibility with previous versions of ASP.NET, to implement the code-behind feature. In ASP.NET version 2.0, you should instead use the CodeFile attribute to specify the name of the source file, along with the Inherits attribute to specify the fully qualified name of the class.

So, I thought I would go ahead and clean up this little bit of deprecated code while I was working on this page.  It sounded like a good idea at the time, and everything ran fine for a while...but a while later, "all of a sudden" I started getting compiler errors saying that "The name 'myCheckBox' does not exist in the current context".  What made this really strange was that I had selected it from the IntelliSense selection list, which is usually very good at only providing names of objects that are valid.  And, on top of that, objects in the .aspx file should pretty much always be available and valid.  In fact, I was not getting errors on any other objects on the page that were being referenced in the routine.

So what happened?  Well, what I found was that my checkbox, and several other controls I had added recently, were not referenced in the .designer.cs file.  Therefore, when being compiled, the code-behind file didn't really know about the checkbox.  It is interesting that IntelliSense was able to recognize it, but the compiler did not.  The real culprit took some effort to find, because quite a bit of real-world time had elapsed between the change which caused the problem, and the change that discovered the problem.

It turns out that simply switching "CodeFile" in the Page directive back to "CodeBehind" and saving it, was enough to trigger the automatic update to the .designer.cs file and it caught up on all objects that were missing.  And suddenly everything compiled fine again.  I don't know why using "CodeFile" caused the automatic updating to suddenly stop, but this appears to be related to the fact that we are using a Web Application Project and not a Web Site.  While writing this blog post, I ran across this post by Steve Smith which appears to confirm that.

So, among the explicit lesson learned above, it also is a good reminder that there is some wisdom in the old saying, "if it ain't broke, don't fix it".  I'm generally in favor of refactoring code, but this was one case where I just threw it in along with a bunch of other changes I was making, and it bit me.  Thankfully the problem came up quickly enough that I remembered having made that change and unwound the issue.  If it had been the last thing I did for a long time on that page, I may never have made the connection.

Twitter Follow-Up

A few months ago, I announced that I was going to do a test-run with Twitter.  So now I thought I'd share a few thoughts.  Probably the most telling bit of evidence that shows how my test of Twitter went, is that I haven't posted anything to my Twitter account since December 5th, a whopping 3 weeks after I started, and two and a half months ago.  It was at that time also that I stopped reading tweets with any degree of regularity.

It's not that I think Twitter is evil or utterly banal (although some of the users may be) it's just that I couldn't seem to make it fit into my life very well.  Maybe I'm just getting old, I am now in the "over 40" crowd, but I had a helluva time keeping up on reading posts, and I was only following about 25 people.  I don't know how anyone follows hundreds of people and actually gets anything else done, like holding down a full-time job and a family.  Granted, I mostly was using my cell phone, and I know there are a lot of little apps out there that I could use to do my twittering on my PC, but frankly, the last thing I want while I'm in the middle of work, focusing on a programming or management task is to keep getting distracted by tweets popping up on my PC screen.  Heck, it's bad enough all the distractions that email from coworkers causes.

It was fun to tweet from the PASS Community Summit and read some others' tweets while I was there, but looking back, I can see that a lot of the tweets were duplicates of others, especially during the Keynote addresses each morning.  And since I was sitting there watching the keynote (as well as adding to the redundant rebroadcast) it wasn't very valuable.

Now, maybe if I was a professional journalist, I would find Twitter to be a valuable source of leads or commentary.  Or maybe if I was trying to market my company, it would be a good way to get the word out and let people know what we were doing.  But for where I am in life right now, not so much.  The one Twitter account that got my attention recently, was the SQLTeam one where Graz has posted several tips, and maybe I'll get hooked again some day with a differently targeted group to follow, and, well, I'll keep my Twitter account in case I want to get back into it, but for now I don't plan to update it very often.

«February»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567