Quite often, .NET Reflector is downloaded in an emergency. Whereas most of the users are developers who use it as a routine to explore objects and methods inside Assemblies, the occasional user is getting it because they are in desperate straits. We've always felt that we, and other NET Reflector users, wanted to hear more about these real-life emergencies, so we sent Richard Morris to investigate.
Not too long ago, Simple-Talk asked seasoned developers for stories about how .NET Reflector had handed them the technological equivalent of one of Willy Wonka’s golden tickets. In this, the second or our “.NET Reflector Saved My Bacon!” interviews, we take a look at the near-disasters that two developers faced, and managed to dodge. First up, we sat down with Christoph Mueller, a .NET consultant, and got down to business:
"I’ve been working with .NET since January 2002 – about the same time that .NET 1.0 came out. Before that I’d spent a couple of years developing ASP and C++/COM applications. Right now I’m manager of a similar team at the IT consulting firm bridgingIT, and still get to spend part of my time developing SharePoint applications — MOSS applications by now, of course."
"The trouble came when we were implementing a SharePoint Portal Server 2003 application (this was in 2004). One of the features the client wanted was a special web part that let the user define special search alerts (basically, finding a variety of products in certain preset categories). The problem was creating that alert. The call to create the Alert object went well, and the alert fired each time the indexer ran and found documents fitting the search query. Unfortunately, calling up the MyAlerts page caused a crash!"
"Going into the debugger and having the application break on each exception was a little tedious, but it finally stopped at an exception related to our problem, within one of the Alert class’s methods. The exception told us that the Alert object’s ApplicationData property (a string) did not have the expected value. Naturally, official documentation never tells you what you need. The only documentation that exists for this string, anywhere, is 'Gets or sets persisted data about this alert.' Fabulous."
"However, the call stack gave us the Alert object’s method and that was when we used .NET Reflector to find out about this method’s source. I could immediately see some manipulation to the ApplicationData property / field. It turned out the correct input for the string was an XML structure of two nodes, with one node containing the length of the query string bumped up by 50. We eventually verified that fact with another alert via the normal SharePoint UI, changed our code accordingly, and things have been working beautifully ever since."
"I felt great when I finally figured this out, and not solving it would have been embarrassing to say the least! Maybe a call with MS-Support would have helped. After all, we weren’t using undocumented features, just poorly documented ones."
"Is there anything I’d change about .NET Reflector? Hmm, yes… well, maybe. Sometimes when I’m out on the road, and my UMTS/GPRS connection is unstable, it wants to connect and look for updates. If the connection and update don’t work, .NET Reflector will just refuse to start. Or at least that’s what it used to do. I admit I haven’t had it for a while, so maybe this kink’s been fixed."
Our second Troubled Tale is from Dan Vanderboom, who has been developing enterprise mobile software solutions for the past five years, and has been working with .NET since 1999:
"Reflector has saved my bacon quite a few times actually, but the closest call came when I was working for a mobile software development company. I had built a small one-off solution for a client, and six months later had all but forgotten about it; it was a short project, probably only a week's worth of my time went into it. But in the switch over to a new version control system (TFS) and a rebuild of my development machine, I had completely lost the entire solution and all source code."
"I might have never known anything about it, except that this same customer called us back needing some urgent modifications, and naturally I was in the middle of a much larger project with nearly impossible deadlines. When I discovered we were missing the source code, I nearly panicked! Luckily, the binaries were installed on one of our in-house mobile devices…"
"I was already familiar with Reflector from my daily use of investigating and learning from .NET Framework and third party libraries. So, I opened the binaries, used the File Disassembler plugin, incorporated the source files into a new project and got it to build again; it was just fantastic! I’d lost all of my comments, and the code needed a little tweaking to get it compiling again, but it saved me from starting from scratch and looking like a fool in front of our customer. Reflector is like a dear friend, and I wouldn't want to program without having it installed and ready in my quick launch bar!"
"As great as it is, there are a few things I’d change about Reflector. When decompiling C# 3.0 code that uses lambda expressions and anonymous methods, I‘d like to see that code as anonymous methods or lambdas, and not as compiler-generated identifiers for compiler-generated classes. I’d make the code look as similar as possible to how it was written. It would also be nice to have some code generation options: should using statements appear inside the namespace block or outside? Should every property or method in a class be preceded with "this." or not…"
"Also, because I often switch between CF 2.0, CF 3.5, and full framework 2.0, 3.0, and 3.5, and now Silverlight versions, the only way I know to get Reflector to switch over is by clearing out all the assemblies in the list, closing out, and restarting. I'd love to be able to switch on the fly, and have it remember my favourite list of assemblies in each mode."