Friday, February 10, 2006

Casting from object[] in C#

Can anyone explane this?
ArrayList list = new ArrayList();
list.Add(new Banana());
object[] areTheseBananas = list.ToArray();
Banana[] bananas = (Banana[]) areTheseBananas; // causes runtime casting exception!
Why doesn't the language allow this?

I know you can do...
ArrayList list = new ArrayList();
list.Add(new Banana());
Banana[] bananas = (Banana[]) list.ToArray(typeof(Banana));
...but in the code I am working with I don't know the type of the array at the point that ToArray is being called.

Thursday, February 09, 2006

Missing method? What missing method?

I just spend the best part of a day tracing down why my unit tests were throwing a 'MissingMethodException' with a description of exactly the menthod that was there. I recompiled, I rebooted, I did everything I could think of. It still didn't find the method. I wrote a simpler test. No good. I ended up with a test that created an instance of the class and called a one line method that just returned a constant int. Still no good.

I explored the assembly that was being created when I compiled with Reflector. Everything was there. All in place. So the assembly was created ok.
So..the hunt was on. What assembly is NUnit picking up?

Eventually.. through the use of fuslogvw.exe and this helpful advice I eventually found it was loading from 'C:\Documents and Settings\nigel\Local Settings\Application Data\assembly\...someplace'. I tried to delete this directory, and couldn't because devenv.exe was using it. So it turns out Dev Studio was helpfully holding onto an old version of an assembly I was working on in a place that .Net checks BEFORE it checks the directory the test assembly was in. How rediculious!

I killed closed dev studio. I killed the devenv process that just kept hanging around even though devstudio was no longer running (nice) and then deleted the '...Application Data\assembly' directory.

This time I run the tests and Ping! lovely green lights.

I mention this so maybe it will save you the 1/2 day it cost me. :)

Monday, February 06, 2006

online calendar with RSS

One of the many projects I have on the back burner (waiting for enthusiasm) is an online calendar/agrigator. is a good calendar (with lots of ajax goodness) and a nice simple plain text way of adding appointments.

GitHub Projects