January 2006 Entries

Wierd Caching

Here is a (greatly simplified) piece of code that has been happily running on 13 production servers for one year. private void DoWork(){    DataObject data = Cache["DataObject"] as DataObject;    if (data == null)    {        InitializeCache();        data = Cache["DataObject"] as DataObject;    }                data.ToString(); }private void InitializeCache(){    Cache["DataObject"] = new DataObject();} The above code has a flaw. We can’t depend on a cached object still being in the cache when we are ready to use it. The code assumes it can place an object in the cache and (almost) immediately pull it back out. Even with the flaw, the code never caused a problem in production environments that log all exceptions.  The...

I Don’t Even Trust My Real Mail Now

I opened a posted letter from a bank today. The letter said I needed to return a form with my name, date of birth, and social security number, or my account might close in 90 days. I thought it was odd that a bank I’ve been doing business with for 5 years didn’t know already know this information. With the ridiculous amount of fraud I see in my email everyday, I was suspicious. I called the bank using a phone number I found on the bank’s secure website. I remained suspicious until I was on hold for 20 minutes. At...

AssemblyVersion and Web Projects

Let’s say you want to add an AssemblyVersionAttribute to a web project. The usual practice is to add a file to the project with the name AssemblyInfo.cs. The AssemblyInfo.cs file will live in the App_Code folder, because that is the only location the new web project model will allow stand-alone code files. The contents might look like: using System.Reflection;[assembly: AssemblyVersion("2.1.1.2")] Next, a web form to display the version number: <%@ Page Language="C#" %><%@ Import Namespace="System.Reflection" %><script runat="server">    protected void Page_Load(object sender, EventArgs e)  {                Assembly assembly = Assembly.GetExecutingAssembly();               string version = assembly.GetName().Version.ToString();                   versionLabel.Text = version;  }  </script>Version: <asp:Label runat="server" ID="versionLabel" /> The above web form will happily...

Two Keys Are Better Then Three

Smart tags appear in Visual Studio when the IDE thinks it can help you make quick work of a common task. I use the feature quite a bit, particularly for rename refactoring, implementing interfaces, adding using declarations, and generating method stubs. One way to open a smart tag is to hover the mouse over a 1 pixel hotspot that lives somewhere in the vicinity of the smart tag indicator. Fortunately, Visual Studio assigns the same keyboard shortcut to open a smart tag as Office apps: Shift+Alt+F10. The keyboard is a better approach, but Shift+Alt+F10 is one of those piano...

Judging Visual Studio 2005

I’ve pounded on Visual Studio 2005 a lot this month. Overall, I’ve been happy with the IDE, and find myself more productive. Stability: GoodFrans has been able to crash the IDE with a brace and with a mouse click. I’m happy I have not found any major problems. I did have a spectacular crash one afternoon with the old “Unexpected error encountered. It is recommended that you restart the application as soon as possible” message (HRESULT: 0x80131527 File: vsee\internal\vscomptr.inl Line: 473). Restarting was not an option as the message kept coming back. I had to kill the IDE, but didn’t lose any...

Visualizers For Web Debugging

Visual Studio 2005 ships with a few handy visualizers for debugging. A visualizer presents a tailored view of an object, which is useful when an object is too complex to fit in a watch window or data tip. Custom visualizers can plug into Visual Studio, see “How To: Write a Visualizer” as a starting point. I’ve packaged up a couple custom visualizers I’ve used recently into a project: WebVisualizers.zip. The ControlTree visualizer shows the hierarchical relationship of web controls, starting with the visualized control at the top. For instance, if you hover over a this reference inside a web form...

Pushing Software Out The Door

A colleague once told me configuration management is to software development what oxygen is to a human. When the proper CM practices are in place, no one notices. When configuration management is non-existent or lacking, the development process chokes. The trick, as always, is to find the right level of process and auditing for the development task at hand. Adam Barr gives us a look at what happens on the extreme end of the spectrum with the release of new Monad bits. Not only is Microsoft big (debug and release builds have to run a gauntlet of tests on 3...

Encrypting Custom Configuration Sections

The ASP.NET IIS Registration Tool (Aspnet_regiis.exe) can encrypt and decrypt sections of web.config. There is no special code required in an application, as ASP.NET 2.0 will magically decrypt sections at runtime. The tool and runtime can also work together to encrypt and decrypt custom configuration sections. So if I have the following in web.config: <configSections>   <section       name="sampleSection"       type="System.Configuration.SingleTagSectionHandler"    /></configSections><MySecrets   FavoriteMusic="Disco"    FavoriteLanguage="COBOL"    DreamJob="Dancing in the opening ceremonies of the Olympics" /> All I need to do from the command line, is: aspnet_regiis -pef MySecrets . It’s easier than a double pirouette…

Some Feedback

I received a nice package in the yesterday. The package was from Judy Calla, who was an organizer at the recent Central Penn Code Camp. The package contained 30 session evaluations with feedback on my presentation. This was the first Code Camp that sent evaluations back to me. I wish more Code Camps could follow up with feedback to presenters. I’m always looking at ways to improve, be it in software, speaking, writing, hitting balls, or home improvement projects with power tools (also known as destruction of property, to those who witness the debacle). The first place I looked on...

Collections, References, and Value Types

Here is a basic refresher on value types, reference types, and collections. The following program executes without any assertions failing. Object.ReferenceEquals determines whether the specified Object instances are the same instance. Good stuff to know before an interview. Update: note John's comment to my post: To say "myValueType1 and myValueType2 DO NOT point to the same object" is a little bit misleading, because myValueType1 and myValueType2 are just different memory regions on the stack, they're not really 'objects', they're most certainly not 'object references'. The process of passing them as parameters to ReferenceEquals causes them to be boxed (thus becoming 'objects' on the...

Choices

Here we are at the start of a new year. For many of us, this is the time to plan and budget for the coming months. One thing is obvious; Microsoft will give us plenty of choices. For example: Which Visual Studio Product is Right For You? Well, it’s a tough choice. My co-workers know me as a Brian, but there is the occasional Saturday night when I want to be a Charlotte. You also have to factor in your options if you are a Microsoft Partner, and later this year we may choose between 20 Windows Vista SKUs. The problem is,...