Posts

Showing posts from July, 2010

Upgrading to ASP.NET MVC 3 Preview 1

Image
Earlier today Scott Gu announced the availability of ASP.NET MVC 3 Preview 1. This release  includes the beginnings of the Razor view engine as well as a bevy of additional features. The following are some notable links with more details: Scott Gu Scott Hanselman Phil Haack Maarten Balliauw Anyhow, I played with the demo and got to wondering how to update an existing ASP.NET MVC 2 project to use the new preview version (obviously I wouldn’t switch production code any time soon…) It was simply a matter of editing my existing ASP.NET MVC 2 (C#) project file and making the following updates: ProjectTypeGuids Replace {F85E285D-A4E0-4152-9332-AB1D724D3325} With {E53F8FEA-EAE0-44A6-8774-FFD645390401} and References Replace <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> with <Reference Include="System.Web.Mvc, Version=3.0.0.0,

"$.validator.methods[method] is undefined"

Image
I’ve started developing a new project and have recently been getting into ASP.NET MVC and JQuery a lot more. To make my life easier I decided to use the JQuery Validation libraries to perform my client side validation. I created a simple registration form with three fields – username, password, confirm password. The following is the code I am using:     The code uses a remote call to the IsLoginAvailable action of the user controller which in turn checks if the entered username has already been taken and wraps the response in a JsonResult. This appeared to work fine (validating the field when focus was lost) but upon submitting the form I received the following error:   "$.validator.methods[…] is undefined"   or   "$.validator.methods[method] is undefined"   After debugging with Firebug I found that the validation was failing on a "data" method. Looking at the code I realized I was specifying the username to pass via the data section in the remote call –

ASP.NET MVC – Object Reference is not set to an instance of an object

Image
In the end I have to chalk this down to incompetence and one of those frustrating error messages that tell you absolutely nothing. I’ve been working on an ASP.NET MVC application and last night decided to use JQTouch to provide an iPhone/Android mobile interface. Doing so should have been extremely straightforward. The planned steps were as follows: Add code in my base ViewEngine to detect if a mobile browser is being used. If so, provide a mobile view rather than a standard one. Create a number of views that use the JQTouch library to format my pages for mobile devices.   I recently came across the Mobile Browser Definition File on Codeplex which can be dumped in the app_browser folder in an asp.net solution in order to provide a bunch of information through Request.Browser. I dumped this into my solution, updated my view engine and implemented a few views with JQTouch. It didn’t take too long and i was feeling pretty good. However, attempting to open my application 

VS2010 Power Tools Extensions are AWESOME

Image
This morning on my daily commute to work I read ScottGu’s latest post detailing the latest round of updates to the VS21010 Productivity Tools extensions. I’m always excited to look at new (or improved) tools that can have a positive impact on my development work and have been very impressed with the powertools thus far. I’m not sure if it is a function of Visual Studio’s extension engine overhaul or simply coincidental, but a lot of really neat new extensions have already been developed for 2010 and to date have been much more useful than their 2008 counterparts. The powertools are a free extension and worth every penny! They contain such gems as Ctrl+Click to go to definition, Triple Click to select a full line of code, Colorized and orderable tabs, and a whole lot more. Today’s update blows all of that out of the water. Mr. Gu went into detail so I’ll keep this short. While there are a bunch of new features in the latest release I am super-excited about additions to the solution

Napkee

Image
Recently I blogged about my experience with a neat wire-framing tool, Balsamiq Mockups. To recap, I loved (and continue to love) the tool with the exception of one design decision - intentionally keeping the tool rough and low-fidelity. Shortly after publishing the post I received a comment asking if I had tried Napkee for HTML wireframe conversion…Following the Anonymous poster’s lead, I managed to procure a review copy of Napkee and am happy that I did. To answer the obvious question: no, Napkee isn’t exactly what I was looking for. But its not far off!! Balsamiq/Napkee Affiliation There does not appear to be any official affiliation between the Napkee and Balsamiq teams, however the following 2009 Balsamiq blog post does suggest that Balsamiq are open to building a community around their open bmml standard – starting with Napkee: http://balsamiq.com/blog/2009/08/05/napkee-launches/ Overview Napkee, as its website says, lets you export Balsamiq Mockups to HTML/CSS/JS and Adobe Flex

SQL Server – Excel Import and Mixed Data Types

Overview I am currently managing a project that, added to its significant development investment, requires a large amount of data gathering up-front. One component of this effort is the importing of information pertaining to each of the client’s physical clinics, parsing the data and pre-populating our database with data necessary to go live on day one. Collecting this data will take a relatively substantial time investment which, fortunately, will be undertaken by the client and not myself! I am, however, responsible for executing the import scripts to perform the data insertions and, as the first completed excel spreadsheets have begun to trickle through, I’ve discovered some issues with the process. Problem #1 – Mixed Data Types Loading the first spreadsheet everything appeared to execute fine, but I noticed that for one of our columns – which can be textual/numeric/alphanumeric – data is not always imported (when the column contains mixed data types). Specifically, some row

ASP.NET MVC Membership Provider Issues

This afternoon I struggled a little with an ASP.NET MVC 2.0 issue. I’m using NHibernate’s export schema capabilities to create my database schema. I have an NUnit project with a bunch of different tests with the sole purpose of re-creating the database and populating some dummy data so that I do not have to do so by hand. I wanted to take this a step further and create some users in my system using Microsoft’s in-built MembershipProvider. Having set up my tests, I received the following message: 'System.TypeLoadException : Could not load type 'OnlineAuctions.Core.Classes.BuyerMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Obviously in this case the system is looking for my provider in the System.Web assembly, not my OnlineAuctions.Core assembly. My config file entry was as follows:   <add name="BuyerMembershipProvider" applicationName="OnlineAuctions" connectionStringName=&quo

Generic ThrowIfNull (C#) Helper Method

For a while now I’ve wanted to write a helper to beautify code like the following: if(account == null) { throw new InvalidAccountException(); } My code seems to be littered with such calls to the point that it feels like unnecessary bloat. While I’m sure there are many ways to get around this (I’d love to hear what they are) in this post I’ll describe a generic ThrowIfNull helper method I’ve created. I’ve seen similar attempts to my own where by default a helper method is used to throw an ArgumentNullException exception but I’ve wanted to be more specific with the exception being thrown. Essentially I want to pass an exception type and a value and, if the value is null, the exception type in question should be thrown. Specifically this is the desired signature: ThrowIfNull<T>(Type exception, T value) Obviously this isn’t a terribly difficult goal to achieve but previous efforts have led me to worry about the performance impact of using reflection to instantiate the desired ex

No pg_hba.conf entry for host

This morning a colleague and I finally had the chance to update our existing Mirth configuration to use a database other than the bundled DerbyDB. While Derby worked fine for a while, we quickly reached the size limit (around 16GB) under which it was able to perform adequately. Mirth themselves recommend using a different database and package Derby, I assume, as a way to get people off the ground without ever meaning it to be used long term. My organization's use of Mirth is still in its infancy and, while we're a Microsoft shop and use SQL Server for all of our database needs, we really didn't want to purchase a SQL server license for this purpose. We opted instead to use PostgreSQL and installed a copy on a virtual server. We ran through the default steps for setting up a Mirth database, including database user creation and execution of the postgresql table creation script bundled in the Mirth installation folder. It looked like easy sailing until we restarted the exist

Getting started with NDepend (part 2 of n) – Digging up Roots

Image
A while back I posted the first in a series of post on NDepend – a static code analysis tool for .NET code. Today it is time to add a second post to the series. If you’re new to NDepend take a quick look at my previous post which should provide a decent understanding of what it can do… Background I have an ASP.NET 3.5 ecommerce website running in production on the internet for a third party who will remain nameless. The site itself is based on the open source nopCommerce ecommerce application which originally allowed me to avoid the plumbing work and focus my energy on the implementation of features valuable to the customer.  Since it’s launch it has done quite well and has required little-to-no maintenance on my part – a happy fact! What I have noticed unfortunately is that I’ve (sub-consciously I think) avoided adding new features or performing any major refactoring since the site’s inception – based, I think, on the fact that the vast majority of source code is not mine and

More MSTest Woes – Location of the file or directory is not trusted

Image
This one was easier to investigate than my previous post . To be fair this one is not the fault of Visual Studio or MSTest. Running my tests I began to see the following error message. Failed to queue test run 'jirwin@mypc 2010-07-02 14:22:48': Test Run deployment issue: The location of the file or directory 'c:\mypath\bin\debug\Microsoft.Practices.Unity.dll' is not trusted. A number of posts online suggested changing the trust levels for specific directories but, having used Vista and now Windows 7 for some time, I correctly figured that the libraries in question (in this case Unity) were downloaded from the internet and therefore were not trusted. Looking at the properties of the files (the above error occurred for a number of libraries) I was relieved to see that my hunch was correct and I would not need to touch my security setting. Unblocking the files (see the screenshot below) fixed the issue immediately. Happy days!

MSTest - Exception has been thrown by the target of an invocation

This week, when attempting to run MSTest unit tests in Visual Studio, I ran into an interesting issue. Whether running the test from Resharper’s test runner or Visual Studio’s in-built test views all tests failed with the following error message: Exception has been thrown by the target of an invocation This is clearly a pretty unhelpful error message – the equivalent to “something is wrong somewhere – please fix it”. Other members of my team were able to run the tests without issue and I was able to run the full suite only last week – leading to the obvious conclusion that my PC configuration is causing the issue. My only recent installation of note has been Team Explorer (2010) for Visual Studio 2008 and, while I’m not sure why this would break my tests (i’m guessing some team build hooks were causing problems…) it was a good starting point. Opening the Team Explorer window I noticed that I was no longer connected to a TFS server. I manually connected to our central TFS se