Archive for April, 2009
NCover Hangs on Configuring Profiler…
Apr 22nd
Our main build broke today. We have about 53 projects in our solution (yes, its huge) and all of a sudden … pow … NAnt started timing out. Upon further investigation I noticed that the build was timing out at the following instance:
Coverage Log: Coverage.Log
Waiting for profiled application to connect…Connected
Configuring Profiler…
It would hang until I killed it or until NAnt timed out (600 seconds/10 Mins). If I killed it, I received an “Object not set to an instance of object” exception.
Digging around some more I found out that others had this very same problem.
Just as they were, I was using NCover 1.5.8, the last free version. I followed suit as them, and used our NCover 2 license for our build server and everything started working again.
It seems that NCover has a critical mass that it reaches and then its like a game of Tumba. It could only handle so much and then it just fell over.
If you’re having this issue, just run NCover 2.
Twin Cities Give Camp Postponed
Apr 21st
It has been moved to November 14th and 15th of 2009.
Why? Get the inside scoop here.
Finding App_Data Programmatically
Apr 14th
While writing some code I needed to be able to access the the App_Data directory in my ASPNET MVC app. Doing this usually involves a Server.MapPath, but this wont work for my unit test.
Here’s how you can get around it:
var appDataPath = (string)AppDomain.CurrentDomain.GetData("DataDirectory") ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
Now I have my data directory for the test as well as during execution of the ASPNET MVC app.
During unit test execution it will be in testing directory while at runtime it will be in the ASPNET App_Data directory.
IoC Auto Registration & Setter Injection
Apr 13th
This post might be useful if you perform auto-registration of your components through an interface. Like this:
AllTypes.Of<IController>().FromAssembly(typeof(Application).Assembly).Configure(reg =>reg.Named(reg.Implementation.Namespace.Split('.').Last().ToLowerInvariant() + "." +reg.Implementation.Name.ToLowerInvariant()).LifeStyle.Transient),
This snippet of code finds all types that implement the IController interface. This would be any controller in your MVC App that implements the Controller base class (Controller implements IController). In this instance the namespace could be something like:
namespace DonnFelker.Example{public class HomeController : Controller{// Actions here}}
Therefore the auto-registration will give this controller a named instance of “example.homecontroller” in the container. This allows me to access it via named instance in the controller. The other thing it does is allow me to access it via the config file.
Why Do That?
I would want to do this because lets assume my application has 30 controllers. I want them all registered in my container, yet I need Example.HomeController to have a setting injected into it. Maybe this is a location of a test server that I use for some ajax communication and I do not want to put this into the appSettings of the config file. I want to put it directly into the object that needs it. An example of this class would look like this:
namespace DonnFelker.Example{public string PreviewUrlFormat { get; set; } public class HomeController : Controller{// Actions here}}
In this case I want to set “PreviewUrlFormat” through my config. I do not want the rest of my controllers to have this property injected. I would use this property as part of view data for some action (perhaps to do some JQuery action in the background against that url). Perhaps I’m doing some rendering at the time the user is looking at an admin page.
Since I’m auto-registring this component I cannot inject anything into it in the config unless I make an entry. Here’s the entry I provided to have PreviewUrlFormat injected:
<componentid="example.homecontroller"service="DonnFelker.Example.HomeController, DonnFelker.Example" ><parameters><PreviewUrlFormat>http://www.example.com/previewfile?fileid={0}</PreviewUrlFormat></parameters></component>
This snippet of configuration will look for the example.homecontroller named instance and then inject the PreviewUrlFormat into the class.
I have omitted the “type” from this component injection because I’m finding the instance via its id.
I hope this helps someone out there.
A Very Cool WCF Tool: WCFTestClient.exe
Apr 10th
This an oldie, but a goodie. Not many people use this tool, much less know about it or where it exists.
By default when you install VS2008 (I’m not sure if its part of 2005 or not) you have a tool at your disposal in the Visual Studio install path:
My Path: c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\
In this path, you’ll find a tool called “WcfTestClient.exe”
It is located here: c:\Program Files\Microsoft Visual Studio 9.0\Common7\ide\WcfTestClient.exe
Fire this bad boy up and here’s the screen you get:

You can add a service endpoint by right clicking on “My Service Projects” and clicking Add Service
Then paste in your service location (I’m using an open one I found on xmethods.net that generates prime numbers):
Click Ok, and the service contract, config, etc will be generated for you and you’ll have something that looks like this:
Double click on “GetPrimeNumbers” and you’ll see the following:
Open the body of the request (as it looks like this service uses message contracts) and where it says “(null)” select “GetPrimeNumbersRequestBody”
Then expand the body and the request what is the highest number the service should search for prime numbers (in english – give me all the prime numbers up to 50):
Click “Invoke”, wait a few seconds and your response will come back.
All Done!
You have now tested a WCF Service without creating an application, generating a proxy, running the app, etc. Super easy!
Other Uses
You could use this to test your own in house services or even to debug a service running on your machine during development (if you wanted to test full end to end). Simply paste in the address of your local service (http://localhost:someport/myservice.svc) and then start testing. This is a HUGE time saver to see if your service works or not. Otherwise you’d have to generate a client, perform a service reference or generate a service proxy, etc.