Making ConfigurationElementCollection Strongly Typed.

I was getting annoyed with ConfigurationElementCollection returning IEnumerable and not IEnumerable, after some Googling I came across this post on StackOverflow https://stackoverflow.com/questions/7991252/read-web-config-section-to-list.

Basically you implement IEnumerable and in GetEnumerator do this

1
2
3
4
public new IEnumerator GetEnumerator()
{
return this.OfType().GetEnumerator();
}

No more casting when you want to use Linq on the ConfigurationElementCollection

Object Reference During NServiceBus Start Up.

One of our NServiceBus services started getting this error today.

1
2
3
4
5
6
7
Fatal    System.NullReferenceException: Object reference not set to an instance of an object.  
   at System.Object.GetType()
   at NServiceBus.Timeout.Core.TimeoutRunner.CacheExistingTimeouts()
   at NServiceBus.Timeout.Core.TimeoutRunner.Run()
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start(Action startupAction)
   at NServiceBus.Hosting.GenericHost.Start() in c:\TeamCity\buildAgent\work\nsb.master_8\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 34

Turns out the NServiceBus.Persistence connection string was pointing to a Raven instance that was turned off.

NServiceBus Testing With Unobtrusive Messages

I’ve just had a problem when using nServiceBus.Testing.

When I was running my unit test i was getting
image

Turns out this service was using unobtrusive messages and it appears that nServiceBus.Testing isn’t aware of that and there doesn’t seem to be a way to make it aware.  Currently I’ve just added IMessage to my messages.

Stop EF Looking for Migration Tables

I keep forgetting how to do this should I’ll post it here.

Database.SetInitializer(null);

Localisation of Built in MVC Validation Messages

While working on web site for a client in Belgium I was wondering why the Required attribute error message wasn’t being localised based on the CurrentUICulture of the thread.

This was bugging me, so I downloaded the MVC 3 source code from CodePlex and found the Required attribute unit test.  Even after changing the thread to use Flemish the below test still passed.

image 

After talking to Damian we found that there are Language Packs for .NET 4.  These can be obtained from https://www.microsoft.com/download/en/details.aspx?id=3324

These packs will install the required resources in you .Net 4 framework directory.
image

As soon as I installed the Dutch language pack the above test failed as expected.

image

I still need to test what gets stored in the logs when these packs are installed and an exception is thrown.  It won’t help us much if errors in the logs start getting stored in the language of the user that is logged in.

Dynamically Add Required Attribute for MVC3 jQuery Unobtrusive

While you can add the data-val attributes for MVC client side validation by default MVC unobtrusive validation won’t process them.

What you have to do is remove the validators and re-add them.

1
2
3
4
$(“#Password”).attr(“data-val-required”, “Password is required”);
$(“form”).removeData(“validator”);
$(“form”).removeData(“unobtrusiveValidation”);
$.validator.unobtrusive.parse(“form”);