Alt.Net day 1

End of day one here in Redmond… only 2 hours of actual Alt.net time and already I am well impressed by the amount of knowledge. A fish bowl session started with C# and it running improvments and possible moves into dynamic aspects…. moving into general talks about languages, their place in a project, stack and programmer general arsenal.
Its also nice to see all these uber smart guy being respectful enough to each to let every one and any one have their say… hopefully this last the weekend!
So far have jumped into the edge of some conversations with the architects of the moment Mr Fowler and Mr Dahan… very cool.

am shattered so off to bed.

Redmond… Hey-O!

Well I have arrived in little old Redmond (next to Seattle), the home of M$ ready to see what happens in this alt.net weekend.
Redmond itself is pretty small and quaint. Oh and its raining. Apparently this is not uncommon. No worries, I’ll be inside most of the time any way.

Ignorance

My ignorance of stuff often astounds me. My complete lack* of understanding of data binding on the UI is hilarious. Our UI guy just schooled me on it and I am very impressed. Just another reason why I think coding in layers is best. We work in verticals so my ui stuff sucks compares to his.. please just leave me in the back end server side stuff. Obviously one could argue that working in verticals means we get exposed to these concepts, but i would rather that be done more formally in weekly code/nerd talks where the UI guy gets up and does a Data binding or Win UI Validation talk , in the same way i do TDD, or WCF or Nhibernate…

OK, not “complete lack”, more “prematurely dismissive” notion 😉

NMock2 RemotingException

Test method XyzUnitTest.TestSomething threw exception: System.Runtime.Remoting.RemotingException: ByRef value type parameter cannot be null.

It turns out that this is caused by not having a return value in the expectation when returning a primitive:

The line of tested code that was failing:

int id = this.Foo.GetId(arg1, arg2, arg3);

The expectation that was causing the failure in the test code was:
Expect.AtMost(1).On(foo).Method(“GetId”).WithAnyArguments();

Need to be changed to:
Expect.AtMost(1).On(foo).Method(“GetId”).WithAnyArguments().Will(Return.Value(Id));

I think this is especially important as a (non nullable) int is being returned so the proxy is treating it as byref, hence it can not be null. This may have been missed if it was returning a object as a null object can be returned in this scenario.

Assembla.com

We have just registered with Assembla.com to manage our international project code base. I wasn’t expecting much, assuming
A: we were paying for it and
B: it would just be an SVN repository.
I have been pleasantly surprised (as both those assumptions were wrong). We are still kicking the tyres but the project management and code check in facilities are nice and clean, not a lot of clutter and provide the experience that i really wanted.
I can see this being a great way for Nick, Gum and I to get working together remotely and getting our code all playing nice. I would be keen to see how i could bolt on some continuous integration to the mix…

Dumb errors with NHibernate

Ok so I was getting “NHibernate.MappingException: Unknown entity class” for a revised/renamed class in my project. “Aha!”, I thought, “its not an embedded resource!”.. and it wasn’t. Re run my tests to confirm update worked… neagtive.
After about 30mins of seraching I noticed I had clipped the name too much and had removed the .hmb. part out of the file name in the mapping file… well thats annoying!

Ayende’s "Unity" review

As per the norm Ayende has some good points
My 2 big issue are the seperation of concerns and error handling.
Just by looking at code that use ObjBuilder (i.e SCSF etc) you know it is using OjbBuilder due to all of the ugly dependecy attributes everywhere, i was really hoping this was not going to be carried into Unity.
As for not throwing an exception on not finding an implementation i find the truely odd default behaviour.

http://ayende.com/Blog/archive/2008/02/24/Reviewing-Unity.aspx

NHibernate many to many collections

We had been having issues with entities not serialising across the wire (yes we are sending Nhibernate entities over WCF services) with not a lot of clues why some worked and some didn’t.

Upon investingation it appeared it was the collections of some of these entiies that were causing the issues, not the enties themselves. I finally realised that we where creating entities for the join tables in the DB (which to me didnt really make sense), thus cause self referencing relationships in the object model, not a good place to be if this needs to be serialised to XML!

A bit of a clean up to the mapping files and we look to be all good.

I am sure this is the most trivial of trival ORM mapping stuff, but it was something that went un noticed around here for months, or at least swept under the rug by those that did.

Below is a the email outlining the scenario….

EMAIL TO WORK TEAM MATES

*If you use Nhibernate or other ORM’s this is of Note, otherwise feel free to delete*

ORM School time:

Background (trivial, but work with me here)

  • We have a whole bunch of Data Entities/ Database Tables that have “one to many” or “many to many” relationships
  • We use joining tables to create these relation ships I.e. to join AssetMetadata & GenreType we use AssetMetadataGenreType table.
  • We use an ORM (NHibernate) to convert the table structure to a usable C# managed code structure.
  • We also use the ORM to map these relationships.
  • Unfortunately we are mapping these tables too explicitly. There really is no such entity as an AssetMetadataGenreType, only an AssetMetadata entity and a GenreType entity. The AssetMetadataGenreType is only a relationship that has no context on its own.

This over eager mapping of joining table may be the problem of our serialisation issues.

Fore example: Currently we have a AssetMetadata entity that then has a collection of AssetMetadataGenreType with each one relating to a AssetMetadata and GenreType entity. The problem here is that every one of these causes a self referencing scenario (AssetMetadata è AssetMetadataGenreType è AssetMetadata). Normally no one would care. Serialisation however does not like this, as self referencing data and XML do not play nice.

Solution: Don’t map the joining tables.

These are not real entities so should not exist in the managed code world. They only exist in the DB thru necessity.

Step one: remove all of these mapping entities (well maybe not delete, but start re-factoring where possible)

Change the mapping so the subject entity knows about its relations. Inverse this relationship in the other mapping files IF NESSECARY. i.e. genre types do not need to know about there related asset metadata

Example below:

<!– The links to associated genres –><!–

–>

<!– RC: 07/02/2008: Trying a different approach so we dont try to pass self referencing data around,

I think this is a dormant issue waiting for collections to populate before it rears up and attacks us–>

<idbag name=GenreTypes table=ASSET_METADATA_GENRE_TYPE lazy=false>

<collection-id column=ID type=Int32>

<generator class=sequence>

<param name=sequence>ASSET_METADATA_GENRE_TYPE_SEQ</param>

</generator>

</collection-id>

<key column=ASSET_METADATA_ID/>

<many-to-many column=GENRE_TYPE_ID class=GenreType fetch=join/>

</idbag>

Another benefit includes faster update times as we are taking advantage of the index of the primary key on the join table.

http://www.hibernate.org/hib_docs/nhibernate/html/collections.html#collections-idbag

I still have to test the hell out of this, however prelim test are all positive.

Rhys

Post sharp

It looks like you can hold a reference to the method you are entering and exiting by using the MethodExecutionTag.
You can assign what you want to it as it is just an object and is bound to the eventArgs of the enter and exit events.
Sweet.
This means you could also make every single method a transaction if you wanted to (if you were Juval Lowy/mad man), or mark entry and exit of a specific instance call of a method using a GUID as colleague had mentioned would be nice for logging.
As this is weaved in to the IL its should have not have any more a negative performance impact on calling the method, over over putting the code in to the method to do exactly the same. You do however have a whole load more flexibility to pull out and put in what you want and where (ie certain assemblies, classes or methods).
I am loving PostSharp 🙂