“Value does not fall within the expected range” while opening a file in Visual Studio 2008

I came across a curious problem a couple of days ago. Visual Studio greeted me with a “Value does not fall within the expected range” when trying to open some of the configuration and text files in one of my solutions.

This occurred even if I closed the solution and tried to open the individual files. ProcessMonitor.exe revealed nothing. Disabling plugins didn’t help. Deleting .suo and .user files didn’t help.

Googling for a solution revealed a couple of patterns. People were getting this either in VB.NET Windows Forms projects, profiling C++ applications or trying to open TFS work items. The latter resonated. TFS, my long-time nemesis, we meet in battle again.

I tried removing the local path mapping for the project in my TFS workspace, deleted the folder and recreated the mapping. Win.

How to nest NHibernate mapping files in Visual Studio projects

Nesting files in Visual Studio projects is as simple as (pun intended) opening your project file into a text editor, finding your reference to a project file and adding <DependentUpon>Class.cs</DependentUpon> within the element.

However, there’s a catch. Nesting the files causes the file names to be overwritten. In this case, the .hbm.xml suffix gets dropped. That effectively prevents Configuration.AddAssembly() from finding the mapping information. A way around this pitfall is defining the dependency as follows:

<EmbeddedResource include="ServiceRequest.hbm.xml">

Thanks go to Sami for cracking this nut with me.

The toolbox

I’m not too big on bloating my Visual Studio with addons and whatnot, but there are a few tweaks here and there. My Visual Studio color scheme is a slightly tweaked version of the Desert Nights scheme by Thomas Restrepo. You can grab it for Visual Studio 2008 here.

I also use the awesome Sonic File Finder addon. It allows you to search for files in your solutions. Programming can be a frantic excercise in jumping between numerous code files and the solution explorer is a really poor way to do it. Most of the time you know what file you’re going for, so just hitting ctrl+, and typing a part of the file name saves you a bunch of time and sanity.

I also used to use the ApexSQL Edit for its superior performance and intellisense feature but it kinda got rendered obsolete after the release of Sql Server 2008 with its built-in intellisense. ApexSQL Diff, however, is a great tool to have in your belt. It does what you’d expect: compares database schemas and merges them. It performs surprisingly complicated merges without breaking a sweat. Both of the aforementioned applications by ApexSQL are of extremely high quality, they perform well and are stable as the negation of something not very stable. Highly recommended.