Posterous theme by Cory Watilo

Filed under: mono

Nancy running on Heroku

Last night Ben Hall blogged about how he managed to get Nancy running on Heroku. It’s still an early experiment, and totally unsupported by Heroku itself, but it is very interesting to say the least.

In essence this means that it might be possible to run any Mono compliant (really guys, you need to pay attention to making this the case for your apps, it’s not much work at all) application on Heroku.

Neat!

-

Nancy is a lightweight HTTP framework for building web services and sites. The framework runs on both the .net framework and Mono.

Detecting anonymous types on Mono

Little more than a week ago, I sat down to add the possibility of using anonymous types as models for views in Nancy. Now, since not all view engines can handle anonymous types as their model I decided I would intercept them, along the way to the view engine, and convert them into an ExpandObject instead.

In order to do this I needed to detect them first, and after poking around the reflection API, and use Google + Twitter to confirm it, I came to the conclusion that there is nothing in there that will tell me if the instance I have is of an anonymous type or not.

Then I got a tweet from Joseph Gray, also known at @MrJosephGray on Twitter, sent me a link to a blog post by Jef Claes titled Checking for anonymous types and it contained just what I needed. It works beautifully, until I ran my code on Mono that is.

Even though the blog post is not clear on it, I was aware of that the detection method relies on undocumented naming conventions and no guarantee that any of the traits, that it checks, won’t be changed in the future by Microsoft. That is also why I was not surprised that there were issues while running it on Mono.

After taking the debugger out for a quick spin it was evident that it was the type name that was the culprit. On Mono (at least on 2.10 that I am running), the name of the generated type contains AnonType and not AnonymousType and it was a trivial task to patch the extension method to check for that as well.

The full implementation that I am using in Nancy is listed below