How often do you see this pattern (or variations on it)

…some code…

Sometimes it will be catch(Exception ex) or catch(SomeParticularException ex), and sometimes it will be throw; or throw ex;, there is no finalizer block, but the important thing is that NO OTHER ACTION IS TAKEN (no logging, no retry, nothing else in the catch block).

As far as I can tell, this is equivallent of wrapping code in NOP (no-operation) commands.

Please don’t do this.

Automated Testing Using WebClient and HTML Agility Pack

I researched options for testing my ASP.NET website. I decided to use Scott Hanselman’s solution where simulate IIS using Cassini and simulate a browser using WebClient.

Good Points
It works!
It’s free!
Doesn’t require a massive refactoring or rewrite.

Cassini should be a singleton. Unless you are testing something that is IIS dependent, you should not destroy Cassini inbetween each test or test fixture.

.NET Attributes to use more often

My theme here are general purpose programming attributes, ones that you might use for any class.

(first seen here)

DebuggerStepThroughAttribute, [DebuggerStepThrough()]
You can still set breaks here, but normally the debugger will fly right over it. Use this when you find yourself running through the same boiler plate code over & over again, especially if the code is machine generated, or otherwise not of interest.

No step through, no breaking, even if you have a breakpoint.


Built in Exceptions you should use

I’ve been using FxCops which looks down on “throw new Exception();”

Here are some more narrow exceptions that already exist in the framework that you should throw, hey it saves you the effort of writing a custom error class.

ArgumentNullException – Argument is null
ArgumentException – Argument not valid
ArgumentOutOfRangeException– arguement too big or small, or not on the list
ArithmeticException — The root of a negative number
InvalidOperationException -given state,

Setting a property that does’t exist at compile time in C#

Let’s say you need to set a property that won’t exist at compile time, but will at runtime, say through the magic of runtime replacing of objects.

System.Reflection.PropertyInfo pi = someObject.GetType().GetProperty("SomeProperty");
pi.SetValue(someObject, "new value", null);

In VB.NET, much easier:

Object o = someObject
o.SomeProperty="new value"

What is Windows Work Flow?

It is like a regular programming language.  Activities = subroutines.  Workflow = a program.  If-Then activities give you control of flow. 

Invocation uses fancy-shmancy object oriented patterns. You invoke a workflow by raising events that pass a dictionary object full of parameters.  You get return values by handling an event that returns a dictionary object full of return parameters.

Another fancy OOP pattern is that the activities behavior is established by setting properties of the activity equal to a function. 

You can also write a work flow as a state machine, which makes it look like a UML state machine diagram.

It is oriented to dealing with human bureaucracy. It is expected that some activities will involve long running processes, delays and people.  If the application has to hand off to a slow human, the whole work flow state can be saved and resumed later.

It is like flow charts.  The workflow model looks like a flow chart that you can attach methods to.  The sequential workflow especially looks a lot like a flow chart. The hope was that line of business experts would draw the charts and developers would then write the code behind the activities.

It is like a server application. However it isn’t necessarily a windows service.  The work flow can have many things happening at the same time (but it runs on the same thread).  Because of the server like nature, you will start a work flow, a separate client application talks to the work flow.

This is kind of like DTS & SSIS.  DTS was mostly aimed at moving data from place to place, but it was graphical, had primative control of flow and it had tasks that looked just like workflow activities.  DTS was not a server application.   SSIS has become a better version of DTS and looks even more like Windows Work Flow– for example, they both use sequence boxes to represent iteration and SSIS has something of a server nature.  DTS and SSIS graphically show you what boxes are executing as the application runs.  I haven’t seen a similar feature with Work Flow.

This is kind of like BizTalk. BizTalk was all about getting the computers organizations to transact with each other.  BizTalk has a somewhat graphical orientation, and used things called orchestrations to layout how computers in one organization would “talk” to computers in another organization.  By “talking”, I mean, invoking a method.  I believe that BizTalk used functoid for what WWF calls activities, but I may be wrong. BizTalk is an expensive product and I’ve never work at a place with a license for it.

Enterprise Library from Patterns & Practices

What is the “Enterprise Library“? Well, look at the .NET framework.  It is big and feature rich.  But what if you want to so something the righ way, like write code with lots of trace & logging commands, lots of try/catch blocks, encrypt lots of potentially secret values, cache stuff for performance or even just retrieve data from the database in a safe, high performance manner?  Well, doing any of these the right way will take ten times as much code.

Every time I catch and error, log it and alert the user, I’m down ten lines of code.  Setting up a stored procedure with parameters is a dozen lines of code, short cutting and using string concatenation takes two lines of code, but is subject to SQL injection attacks.  Encryption, again takes a couple of lines of code each time it is used.

The solution is to use the Enteprise library, which provides a layer on top of the .NET frame work that cuts the number of lines of code it takes to log and event, call a stored procedure or encrypt a string.

JScript.NET + SMO

This could be a cool combination– Javascript, that language we all so painfully learned just before we all realized that Javascript code can only be expected to run on one browser, plus SMO, the object oriented way to talk to SQL server. It beats some of the options, such as batch or sqlcmd. Well I don’t know about enough about sqlcmd. Or JScript.NET. works at the file level, although files can now “import” a .NET assembly.

With the help of “external commands” and a customized tool bar, I quickly was able to get away from the command line and do most things in Visual Studio 2005.
For a Jscript.NET program, the .exe is the project. This is important to understand. If that .exe has a .pdb file (debugging symbols) in the same directory and if you open the original source code page for the .exe, you can debug that file with breakpoints, step through and all the other things you get when debugging something like VB.NET.

Not being able to do that, in my opinion was javascript greatest weakness. Just writing a bunch of alert(x) commands doesn’t cut it for a debugging experience.

Unfortunately, the greatest weakness of JScript.NET is that it doesn’t have intellisense. Might as well use C# if you are using more than a few objects and properties.

If the code snippet manager is hidden…

The code snippet manager sometimes fails to show up on the “Tools” menu of Visual Studio 2005.  If it does, go to Tools/Customize, select the tools category, find “Snippet Manager” drag out of dialog window and up into the menu.  The operation is a bit like the MS-Access menu designer if you’ve ever used that.