try-catch-FAIL

Failure is inevitable

NAVIGATION - SEARCH

Why Microsoft instead of "Open Source"?

Recently, one of my friends asked me why I was a "Microsoft" coder instead of joining the open-source camps.  I think that's a great question, but it's really two questions: how did I end up as a "Microsoft" coder, and (the more interesting question) why have I chosen to remain a "Microsoft" coder when there are so many cool buzzwords popping up?  I may get in to the former question some day, but for today, I thought I'd run through the top 5 reasons why I am, and will remain for the foreseeable future, 100% entrenched in the Microsoft .NET world of deve... [More]

Using Java APIs in .NET

Have you ever found a neat-looking API that would save you tons of time and pain, only to have your hopes crushed when you discover that the API is written in Java?  Well, fret no more, because there’s a nice, easy way to leverage tasty Java APIs from within .NET: just compile them to IL using IKVM.NET! I’m currently using the excellent Weka machine learning library from .NET.  Here’s the code: 1: /// <summary> 2: /// Simple ad-hoc class for testing out the Weka API from .NET. 3: /// </summary> 4: public class AdHocTests ... [More]

Addressing Two ActiveRecord Annoyances

I still [less than three] ActiveRecord, but the honeymoon is definitely over.  Over the past couple of days, I've run into a couple of issues that took some thinking to address.  Neither is a deal-killer (not in my opinion, anyway), but they are problems that need to be solved. ActiveRecord persists changes without you telling it to Take the following code snippet: 1:  2: int id = 0; 3:  4: using (new SessionScope()) 5: { 6: Widget w = new Widget(); 7: w.Name = "My Widget"; ... [More]

Walking a tree with yield return and recursion

C# 2.0 introduced the "yield return" statement.  While neat in theory, I actually never ran into a scenario where I needed it.  I had heard all the rage about it, but to me, it was kinda like the 5th wheel on the cart of awesomeness that was C# 2.0.  My opinion changed this morning when I needed a simple way to depth-first iterate over the items in a tree. My original solution was to use a stack, build up a collection of the nodes in the tree, then return the collection, but that actually didn't work too well in my case (I was doing something screwy with the collecti... [More]

Castle ActiveRecord: Quite Possibly the Greatest Thing Ever

Well, maybe not, but it has quickly become my favorite tool for writing .NET applications.  I've been using it to write the persistence layer for a brand-new enterprise application we're building, and so far, it's elegantly supported every single thing I've wanted to do.  LINQ?  Got it.  Part-of relationships?  Easy.  Many-to-many?  No sweat.  Multiple data sources?  Simple.  Validation?  Available.  Some may argue that using something like ActiveRecord is bad because it requires you to use inheritance, and while that may be true so... [More]

System.Diagnostics.Process class woes resolved!

The Process class is useful any time you need to spawn off a child process.  Sometimes you don't really need to couple the parent process too tightly with the child process, but other times you may need to directly tie in to the standard input/output and manipulate the child process.  One of the recurring gripes I hear from people that have had to capture output from another process using the Process class is that it seems to randomly fail to capture all the output.  I have been struggling with this issue causing fluke crashes for a couple of weeks, but I'm happy to report I hav... [More]

Using Castle ActiveRecord with multiple databases

I <3 Castle ActiveRecord, but today I ran into something that I couldn't quite figure out.  The solution from the documentation was seemingly incorrect.  After much trial-and-error though, I have it figured out, and it turns out the docs were right, and I was wrong.  I'm documenting exactly what I did here in hopes that it might save someone else some pain someday. The problem was that I needed to create ActiveRecord types that were backed by two different databases.  I'm not talking about a single type that pulls from both databases (not sure how that would work), I'm ... [More]

Creating a reusable GridTreeView with ASP.NET MVC and jQuery, take two

In my last post, I created a partial view page that rendered a collapsible gridview (which I now call a GridTreeView) using the MVCContrib Grid HtmlHelper extension and the jQuery  ActsAsTreeTable plug-in.  While the code works, there are a few drawbacks.  First, I completely forgot about having to link the CSS file in to the view.  That's doable using the view codebehind, but I don't like codebehinds in MVC.  The second drawback is that it doesn't follow the "standard" method of rendering controls in ASP.NET MVC.  All the built-in controls are available... [More]

Creating a reusable grid tree view with ASP.NET MVC and jQuery

I think it is a safe assumption that every web developer has had to display tabular data at one point or another.  Tabular data is easy with ASP.NET: bind a GridView to a data source, and you're all set.  But with ASP.NET MVC, things are a little trickier.  We don't have access to all the nice WebForms controls.  Still, it's fairly easy to do: just write a for-loop, or better yet, use the grid helper from MvcContrib. Things get a trickier though if your tabular data is also hierarchical.  Typically, we display hierarchical data in a tree of some kind, but trees really... [More]

Simplified web application packaging with MSBuild

In a previous post, I described some of the pain I've run into with using Web Deployment Projects.  I have given up on that solution and have instead rolled my own.  I'm happy to report that I now have a much better process (in my opinion), and one that didn't require nearly as much beating my head into the keyboard.  First, you will want to grab the MSBuild Community Tasks.  These will enable you to do some nice things like grab the revision of your local Subversion checkout and update files as you "package" them. Now, let's think through what we want this scr... [More]