Object Reference Not Set to an Instance of an Object

I gotta tell you, if there is one killer exception message that n00b programmers bitch about, that's the one. And 99 percent of the time, the real problem is what's between the keyboard and the chair!

Look, if you get this message it means you tried to use an object variable that's null. If it's null, that's either because you have a coding logic error that's allowing it to come back null, or some condition that you didn't forsee brought it back null and you didn't have defensive code to check for this. If it legitimately can come back in a state of Nothingness, then you need to test for that and code the rest of your logic accordingly. You CANNOT assume!

Wanna know something else? Out of those 99 percent, a similar percentage of programmers have not taken the time to wrap their code logic in a Try / Catch or Try / Catch / Finally block.

If they did, they wouldn't be posting inane questions to forums and newsgroups about it! It's OK if you are like totally new and this is the first time. But if you are the kind of person who cannot learn the lessons of history, I don't feel sorry for you being doomed to repeat it.

Look, here's the pattern. It doesn't matter whether its VB.NET, C#, whatever:

' Your potentially buggy code here
Catch ex as Exception
' put a breakpoint on the next line so you can see what happened, D00d!
System.Diagnostics.Debug.WriteLine (ex.Message & ex.StackTrace)
End Try

Do this with ALL of your code. Learn to wipe your own butt. You will thank me later.

Your Mantra is: trycatch, and if you do this again I'm gonna send Chuck Norris out to fix your fyookin' computer, OK?

N.B. The post isn't even 4 hours old, and already I'm getting flamed by comments about not illustrating catching for the specific exception type. Look, we are dealing with a post oriented at complete n00bs who need to learn what an exception is first. Nobody is pontificating here - I was one of those, once. Then we can get to the next level. My point is that learning to catch and examine exceptions is a useful debugging tool as well as being a valid programming construct. The comments are, of course, right on the money, but my fear is that they will take us off the primary topic, which is - learn how to debug your own code!


Blue-Hat SEO, RPC Ping, and Metrics

"Pluck your magic twanger, Froggy!" -- Andy Devine

Recently I started playing with some ideas on using RPC Ping endpoints to help promote one of my websites, ittyUrl.net. For those who aren't familiar, it is customary to ping RPC servers with the title and url of a new blog post. Most Blog hosting software already has this built in. But - it also works for websites with articles, forum posts, or that display custom search results, like mine does.

The idea is that these RPC servers will be prompted to go out and request your post and they'll index it, and many sites (some not so noble) will pick up the links and essentially you have gotten yourself some free backlinks (of course, backlinks with a low or no PageRank can actually do you harm from an SEO perf standpoint, but that's a separate issue).

One example site that more or less picks up everything for you is weblogs.com. They have a "rolling" display of all the ping updates they've gotten, and you can download OPML-format XML files that list everything. The smaller one is less than 2MB - but that's sufficient to go link crazy. One guy even recommends on his blog that you should take these titles and replace the url of the link with your own custom scraped content, create a "rolling xml feed" of it, and ping the RPC servers with your feed. That's a little more like "dark grey" SEO to me, but - hey -- whatever floats yer boat!

A service that "combines" reliable RPC servers in one shot for you is Pingomatic. You put in your title, link and optional RSS feed url, check off all the services you want them to ping, and they take care of it. I've automated this process with a little "Pinger" fire-and-forget delegate wrapper class. But essentially what you can do (to make it easy) is take the required GET url and use it as a template like so:

Then, all you need to do is String.Replace the "blogname", "bloggurl" with your dynamic custom items and using the WebClient class, do an HTTP GET with the "DownloadString" method and check your results.

I should hasten to add that you want to do this on an individual basis as each article, forum post or blog post is added. If you try to do a bunch at a time, you are going to start getting some of those "Slow down, cowboy! - you just sent one, etc." messages. Here is example code:

public static void PingOMatic(string title, string url)
pingoMatic = pingoMatic.Replace("blogname", title).Replace("bloggurl", url);

WebClient pingoWc = new WebClient();
string pingoString = pingoWc.DownloadString(pingoMatic);
System.Diagnostics.Debug.WriteLine("pingomatic--" + pingoString);
catch (Exception ex)
System.Diagnostics.Debug.WriteLine("pingomatic--" + ex.Message);

I call the above using my Fire and Forget delegate wrapper so it's a non-blocking call.

You could also put this into your blog template in an invisible IFRAME whose src attribute points to the pingomatic GET url with the (example, Blogger) template Items in the place of the replaceable items and every time somebody reads a post on your blog, the RPC server list gets pinged.

You might be wondering what is the result of this. Well, its very early in the game, but here is a pic of adsense Page View traffic for ittyurl.net after I installed this code:

The big shot upwards at the right is what happened to traffic after I started the pings on each new unique search that users make on ittyurl.net's search page. Traffic literally tripled from its current level within 3 days. Of course, a lot of that is the ping requests from the ping servers, but you get the idea. Regarding what may happen to revenue, it's too early to tell, but there is no doubt that this will increase your traffic.

One of the interesting side effects of this is that the googlebot will come and visit almost immediately after one of these little ping sessions. I've also noticed that either googlebot or some other bot that's picking up these links makes "bogus searches" that might have search terms like "fcjghri wxhtyuio". I haven't figured this out yet, but at present it is only a minor annoyance.

The bottom line of this, as the title suggests, is metrics. Everything that happens on that site is logged into the database, and i can do all the statistics and metrics I want with simple SQL - to find out EXACTLY what is happening on my site(s).

N.B. Here is a chart of daily clicks (Adsense) up to 7/12/2007, which clearly shows that the increased traffic is not just "RPC Ping robotics" but real people clicking on ads:

N.B. The ShortChanges xml feed for weblogs.com is now here.

In Other News . . .

I just read where Microsoft has switched 79 of the 80 boxes that power microsoft.com to Windows Server 2008, leaving just one on Server 2003 so they can compare. I'm downloading it as I write. As long as it will upgrade over Windows Server 2003 x64, I guess I'm ready.

N.B. Installed Server 2008 Enterprise x64 last night, started around 9PM and I think it finished sometime around 1AM - I was asleep, but it took care of the rebooting and all by itself. This was an upgrade over Server 2003, and it went very smoothly. All my software is still there, and it all works! Have to search for some 64-bit audio and video drivers to finish up, but that's a minor issue and to be expected.


Visual Studio Mobile Apps for Blackberry?

"Rudy's arrogance has gotten the best of him. How can a man who failed to prepare New York City for a second attack after the first one, who sent firefighters and emergency workers into Ground Zero without respirators and quit the Iraq Study Group to raise money keep America safe?" -- DNC response to Rudy Giuliani presentation alleging Clinton failure to respond to terrorism

Yep. On the C# newsgroup, one poster provided a link to "Flowfinity":

"Flowfinity Blackbird is an add-on to Microsoft® Visual Studio® 2005 that empowers ASP.NET developers to deliver "Wireless-Ready" applications for BlackBerry®. Using unique features of Visual Studio 2005, Blackbird shortens the BlackBerry application development learning curve for Microsoft .NET developers."

I haven't tried this yet as I have no current need to target Blackberry devices. But, he claims to have developed several applications using it.

To get into a little more detail from the FAQ:

To access Blackbird applications, users need to install Flowfinity Client on their handhelds. Administrators install ASP.NET applications with embedded Blackbird runtime on their IIS servers. User authentication and authorization are handled by IIS similarly to traditional web applications.

BlackBerry only supports Java, so how does Blackbird convert my .NET code to Java code?
Blackbird does not convert any .NET code. All code remains in the original .NET assemblies and gets executed on the server. Blackbird replaces web browser and HTML rendering components of traditional ASP.NET applications to provide "wireless ready" user experience optimized for wireless handhelds.


Global Warming, Stock Market, and Data

"Oops! Wrong hat..." -- Bullwinkle

It's interesting to observe the global warming debate and how easy it seems to be for various proponents on one side or the other to replace science with emotion - to the point of virtual hysteria in some cases (see my post on Al Gore).

I remember when I was doing research for my Ph.D. thesis, my faculty mentor and professor, Dr. James Gould, would exhort me "not to give up, finish the job" -- mostly because the data collection process was so time consuming and lengthy, and consequently I would occasionally get discouraged at how much work it can be to put together a first rate dissertation.

I was collecting daily solar radio output data from NOAA, and developing programs to do all kinds of mathematical calculations on same (FFT, autocorrelation, various filters such as stochastic and Kalman, etc.). In this collection and research process I became acutely aware of the effect of the Sun on earth's climate, weather, and even our economic processes - at least, that's what the data would lead one to believe. You need to go back 10,000 years on this global warming stuff to really find out what's going on. 50 years simply will not cut it. Yet, the "respected" body of the scientific community would have us believe that this is sufficient to make pronouncements that can have potentially devastating social and economic impact on you and me!

At this same time I was doing daily tree readings with a Radio Shack millivoltmeter. That's right -- the electric potential of plants is influenced by the Sun's output, as is the biochemistry of and even the collective mass behavior of humans. It was uncanny how the rate of change of tree potential would associate with the rate of change in say, the DJIA. I eventually gave this up after a year or so as I had put myself in the position of simply collecting "too much" data, and I reasoned that some of it could be flawed.

This is not uncommon -- as a developer of computerized stock trading systems at Merrill Lynch, I had the opportunity to see some systems where the statistical work and computations were quite flawed.

Along this path I became aware of the work of researchers like Theodor Landscheit. My research eventually led to a model which correctly predicted the long term decline of interest rates through the 1990's.

My point here is that it is extremely easy for "experts" to relegate themselves to focusing on the hole instead of the donut, and end up with inaccurate determinations. At this point, add in a little mass hysteria and you've got a real mess on your hands.

People - whether they be journalists, lawyers, scientists, politicians or software developers - need to be mindful of the fact that the data we have collected on our subject may either be flawed, or that the determinations we've made using this data are flawed. Consequently it is important not to "go off" based on these determinations without taking the time to examine our "facts" very carefully and in as objective a manner as possible. The process of collecting, analyzing and examining the collected data must be totally rigorous and unemotional.

By the time we actually get around to doing something meaningful about the global warming crisis, we will have already entered the beginning of the next Little Ice Age. I am serious: don't sucker for this "global warming" hype until you see real facts going back to the last Ice Age. And, as I mentioned in the other post, "That ain't hot air"!


Windows Vista: Internet Explorer 7.0: Cannot open Internet Options

"No price is too high to pay for the privilege of owning yourself." -- Nietzsche

And so continues my never-ending love/hate saga with Windows Vista:

You try to open Internet options From the IE Tools menu, or from the Control Panel Internet Options applet. In IE, you get a dialog box "this operation has been canceled due to restrictions ...". In Control Panel, it just silently fails. Yeesh, methinks - more Vista BS!

Well this just cropped up on my Vista box (or at least I just noticed it). So after not directly finding anything with a few well-placed searches (which right there indicates it's probably a fairly new issue), I decided to start undoing some of Microsoft's little "hotfixes". The latest crop were all installed on June 13, 2007 and the ones I removed include these KB numbers:


I'm sorry I cannot be more specific, but I'm not gonna reboot after every single one. I uninstall four to six at a time and then reboot.

At any rate, it was one of the above, since now I've got the functionality back -- AND I've run a special ERUNT Registry backup to preserve it. I have System Restore turned off - for reasons I've detailed in a previous post. In fact, I've done about every fix detailed here to improve Vista performance.

To uninstall updates / hotfixes, you have to click the "View Installed Updates" link in the Control Panel's Programs and Features applet.

You guys test those security hotfixes, right? I run with User Account Control off. Maybe they just didn't test for that...

Incidentally, there is often a supported hotfix for many of these issues, but you have to go through a lot of trouble with Product Support to get them. Here is a site where many of these are contributed by users. Microsoft also now publishes a number of these as well on this page.

Also, Sandi Hardmeier is an MVP who runs a Vista / Internet Explorer - related hotfix site.


I reinstalled the above Windows Updates, one - by - one, rebooting as instructed each time. This time, after testing every one, I no longer experience the described problem. This took me two hours of my professional time.

Who do I send the invoice to?


The Arrogance of Complacency

Nobody in the game of football should be called a genius.
A genius is somebody like Norman Einstein.
- Joe Theismann

Time machine: It's 1986. I'm on the 20th floor of an office building in downtown Orlando, where I work as a commercial real estate and mortgage broker for a national real estate firm. The top music video on MTV is Steve Winwood's "Higher Love" with Shaka Khan on backup vocals. Ella Fitzgerald , First Lady of Song, has died.

We are looking out the office window at the Challenger shuttle takeoff, and suddenly there is a large voluminous plume of white smoke going off in all directions.

I was the first and only one to say to my co-workers, "Something is wrong. I think the Shuttle just blew up." I believe this is when I first became aware of the arrogance of complacency. The reports that came out later, and the Columbia disaster report from the more recent disaster, were eerily similar:

"For both accidents there were moments when management definitions of risk might have been reversed were it not for the many missing signals -- an absence of trend analysis, imagery data not obtained, concerns not voiced, information overlooked or dropped from briefings..."
the report said.

There are parallels in the software development industry as well as in other industries. The Arrrogance of Complacency is partly responsible for Boeing being able to eat Airbus's lunch, and for companies who have otherwise great products and ideas that fail. To the outsider, it's often quite obvious what is wrong and yet, the insider's mind is so clouded by the Arrogance of Complacency that they fail to even get a hint. They are rearranging the deck chairs on the Titanic in the false belief that they are moving forward and progress is being made.

And of course, most recently, we've got computers that won't reboot up at the Space Station.

The signs of the Arrogance of Complacency are obvious enough: Managers / business owners who seem to have some kind of "holier than thou" attitude; who refuse to recognize / admit that their original business or marketing concept is no longer working and needs to change, who bully others in their organization into submission to their will.

Not long ago, I worked for a company that suffers from the Arrogance of Complacency: a company with a technologically superior product and the potential delivery system to bring it to profitable fruition. And I saw all the symptoms as I watched this company literally wither away and its stock begin to plummet as investors began to realize that management simply was too arrogant (and complacent in its position) to have a clue about the most basic things it needed to do in order to move forward. I'm talking about really basic things: A four year old startup that still cannot even do billing? With a top company official who believes the way you make your stock go up is to put out exciting press releases..

From the development perspective, you may see projects that are completed and tested, yet never seem to be able to make it into production, and you may see a lot of what I call "band-aid code".

While this is more of a philosophical concept, it still holds great import for you and me as programmers. When you see the signs, it's an almost unmistakeable metaphor for "time to get out of Dodge".


ASP.NET: Get MAC Address of Adapter, and Control.Invoke

using System;
using System.Net.NetworkInformation;
using System.Web;

namespace MACAddress
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();

Response.Write("Interface information for "+ computerProperties.HostName + ": "+ computerProperties.DomainName + "<BR/>");

foreach (NetworkInterface adapter in nics)


IPInterfaceProperties properties = adapter.GetIPProperties();

Response.Write(adapter.Description + "<BR/>");

Response.Write(" Interface type .......................... : "+ adapter.NetworkInterfaceType.ToString() +"<BR/>");

Response.Write(" Physical Address ........................ :"+ adapter.GetPhysicalAddress().ToString() +"<BR/>");







Visual Studio 2005 developers have learned that 2005 is a lot more picky about attempts to update a control property in a Form from anything other than the UI thread the control was created on. Here is an elegant way to do this that is very adaptable and re-usable:

delegate void SetValueDelegate(Object obj, Object val, Object[] index);

public void SetControlProperty(Control ctrl, String propName, Object val)
PropertyInfo propInfo = ctrl.GetType().GetProperty(propName);
Delegate dgtSetValue = new SetValueDelegate(propInfo.SetValue);
ctrl.Invoke(dgtSetValue, new Object[3] { ctrl, val, /*index*/ null });

// Usage: SetControlProperty(label1, "Text", myString);

That's it! Works with any control, all you need to do is get the control name, the property name (in "quotes") and the value correct.


GotDotNet.com User Samples not going away?

From the site:
"User Samples phase-out – Schedule update in Fall ’07
We will not phase-out User Samples until we can provide customers with a great alternative. We will update you with further schedule information in Fall, 2007."

That's really good news to me. I've got samples I've uploaded there that have been downloaded over 52,000 times. And I cannot tell you how many great pieces of helpful code I've downloaded from other kind souls who want to share their work.

Thanks, Microsoft. You got this one right. In fact, there have recently been fresh uploads of samples in the User Samples area at gotdotnet.com!

Codeplex is great - but not for sharing user samples - unless you want to move the whole gotdotnet.com section there.


Greetings from Orlando! (and IPV6 addresses, and "Don's Shell"...)

A man speaks to his doctor after an operation. He says, "Doc, now that the surgery is done, will I be able to program in C#?" The doctor replies, "Of course!" The man says, "Good, because I couldn't before!"

Yes, Tech-Ed is in Orlando once again!

Q. Are you going to be there?

A. No, but I do live in the Orlando area so I'll be at the Influencers party at Margaritaville Wednesday evening

Q. Then why did you post "Greetings from Orlando".

A. Every other slob in the Universe seems to think it's important, and so i didn't want to be left out.

Q. Why aren't you going to be at Tech-Ed?

A. I'm very busy. I'm writing code. And frankly, I'm "conferenced to death" and need a break. To illustrate my point, I went over to the Convention Center to pick up my ticket to the influencers party. I saw a lot of .Netters walking around at Tech-Ed. Most of them looked downright tired! Besides, Dr. Dotnetsky told me not to go, and I respect his opinion.

There! Now that made me feel better!

IPV6 Address Issues

Q. Why does "Request.UserIPAddress" returns an empty IPV6address when I run (both serve and browse) my asp.net app on WindowsVista? It all works fine on Windows XP Pro: a regular IPV4 address isreturned.
How can I force the code to always use the IPV4 address, even onWindows Vista?
A. (via Mark Rae on dotnet.framework.aspnet):

using System.Net;

public static string GetIP4Address()
string strIP4Address = String.Empty;
foreach (IPAddress objIP in
if (objIP.AddressFamily.ToString() == "InterNetwork")
strIP4Address = objIP.ToString();
if (strIP4Address != String.Empty)
return strIP4Address;
foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
if (objIP.AddressFamily.ToString() == "InterNetwork")
strIP4Address = objIP.ToString();
return strIP4Address;

Visual Studio Shell

This is kind of interesting, because at the Influencers party, I ran into DonXml (Don Demsak, the "east coast Don") and he was babbling about how he wanted to extend VB.NET with his own keywords. Of course with a Margarita and a couple of beers already washed down, I almost thought he was kidding. At least, I thought he was babbling, but he actually wasn't....

Microsoft is now coming out with the "Visual Studio Shell" - essentially a streamlined Visual Studio development environment that you can customize with your own language, product or application. "Created in response to requests from our partners, the Visual Studio Shell gives you the option of integrating your tools with Visual Studio or creating an isolated, custom-branded application..."

So Don, innovator that he is, was actually not far off base at all. Interesting.


Microsoft's "Shared View" likely to be a Hit -- and "Less is More"

Microsoft has come out with a beta of it's Live "Shared View" application. This will probably seem reminiscent of Remote Assistance (Terminal Services, Remote Desktop, whatever name you may be familiar with).

However, it offers some interesting new features. First off, the program is advertiser - supported (at least in this iteration) and is free to download and use (that's right - free - as in "beer").

You can share just an individual application, or your entire desktop, with up to 15 other participants. You can invite attendees via Live Messenger or email. It works very nicely - in fact I tried it out today with a work partner and it worked seamlessly right through the corporate firewall -- and doesn't seem to take up a lot of resources. Plus, when you are connected, users can switch control - one user can share their desktop, and then the other user can choose to switch "sharing" and share their desktop instead with the first user.

I predict this is going to be an instant hit! Currently, this only is supported on 32-bit platforms.

Go snag yourself a copy at the above link and have fun sharing!

Less is More

Recently I got off an IM conversation with MVP friend Rick Strahl. Rick and I were ruminating about how much "stuff" has been coming out of Microsoft, and how much of it you are actually going to end up using in production. I mentioned that my goal was to use WCF for a production app this year. I'm still trying, but honestly I confess that sometimes I wonder what it is going to buy me. I also mentioned that I'm currently working on a web application for a major national client where one of the inbound data feeds is "POX" - plain old xml - no SOAP, no webservices, just a REST-ful API. Rick agreed, explaining that he's been doing stuff that uses REST with FLASH api's and that it is easy, and FAST. One of the things I respect Rick for the most is that he is not only a very smart developer who is capable of intense innovation, but is also willing to openly question anything -- even if it goes against the grain.

Less is more? Think about it. I'm not an evangelist of APIs or frameworks, but I've been saying this for a long time. What I'm saying, I guess, is that it's great to have all these wonderful new frameworks and bleeding - edge stuff to glue apps together with. It's not always easy to put them into the pot without it blowing up in your face. Sometimes, the simplest is the best. You just have to look at the situation, educate yourself as best you can, and make a decision.