Bang! Bang! your dead

I found an obscure bug today, a typo no less, but Im getting ahead of myself.
It turns out that C# allows you to use multiple not operators (!).

So:  true == !!true and false == !!false

Why you would ever want to use this is beyond my small level of comprehension, but it made finding my bug a little harder.

if(!X and !!Y) then do something

it turns out it was meant to be
if(!X and !Y) then do something

The double bang is easily glossed over as your eyes are looking for its presence not checking there is a correct count of bangs.

 

FileMon and FileLoadException

We deal heavily with dynamically created assemblies. We do system installs of our product almost never.
When we do I always encounter the dreaded FileLoadException Setup failed with hr = 0x80070005

For some reason the binder uses an obscure directory that does not have the correct permissions for ASPNET user to access. Which directory? I can never remeber.

Filemon from sysinternals does… it’s great (and free). It shows you all file access commands issued and whether they succeded or not. So its easy to find where your access is being denied.

In this case “c:\documents and settings\Default User\local settings\Application Data”

NUnit and Dynamic Object Creation

I have had a couple of tests failing for some time that I could not fix. I came back to them today and have still not got very far. The code that fails during testing, only fails during testing and I can only guess it has something todo with the way NUnit loads the assemblies.

My problems:

ConstructorInfo constructor = systemJobType.GetConstructor(typeArray); – returns null during testing
Activator.CreateInstance(systemJobType, getConstructorArguments(node)) – returns null during testing(IEventHandler)Activator.CreateInstance(handlerType);- doesn’t return null but the cast fails during testing

The commonality in these lines is that they all use interfaces. The first two lines are trying to do the same thing in different ways, create an object that takes an interface as an argument. The use of interfaces is obvious in the second line. The interfaces are different but they are all in different assemblies to where the code is running, although they are referenced.

So im still stumped….

Is it just me?

… or is XML a really stupid choice for Build Scripts?
Im sick of writing NANT scripts in XML.

I guess it’s just me as there is almost nothing around that doesn’t use XML, at least in the .NET world.