MonoDroid and MonoTouch Alive!

by jmorris 20. July 2011 22:11

There was a lot of noise and confusion on the Monodroid mail group when it was reported that Novell had been sold to Attachmate and subsequently laid off the entire Mono team. The two major products that the team had been working on, Monodroid and Monotouch (cross platform .NET platforms for Android and iOS development) apparently were dead.

Well, it looks like Miguel and his team have worked a deal with Attachmate:

Through an agreement with SUSE*, a business unit of The Attachmate Group (the company that acquired Novell in April 2011), Xamarin has a broad, perpetual license to all intellectual property covering Mono*, MonoTouch, Mono for Android and Mono Tools for Visual Studio. Xamarin will also provide technical support to SUSE customers using Mono-based products and assume stewardship of the Mono open source project

- http://blog.xamarin.com/2011/07/18/first-press-release/

This is good news indeed for open source .NET development and all involved.

Tags: ,

Android

The Mysterious +<>c__DisplayClass1

by jmorris 9. July 2011 01:23

While unit testing a a VirtualPathProvider today, I came upon an interesting exception:

System.Runtime.Serialization.SerializationException : Type 'Foo.Web.Core.UnitTests.Plugins.Modules.PluginRegistrarTests+<>c__DisplayClass1' in assembly 'Foo.Web.Core.UnitTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

I was stumped by this…what, where and who  is +<>c__DisplayClass1'? Granted my scenario was somewhat complex in that I am testing in a by using a fake AppDomain that mimics the ASP.NET HostingEnvironment ala this post.

When I saw that error, I immediatly thought the problem was that I was missing the Serializable attribute, since the exception explicitly states: “[type] is not marked as serializable.” I added that attribute to class that I was loading into the faux AppDomain for the same result:

image

WTF? I was stumped! I googled around a bit and got side tracked by some discussions of MarshalByRefObject and finally stumbled upon something on Ode2Code. I wasn’t quite sure of what the problem was until I read some of comments. Most notable this one. A quick check of the IL with ILSpy confirmed my suspicions:

image

Fix was easy: simply move the declaration of the FakeHttpApplication class to within the scope of the delegate itself. Here is how I had it defined:

image

And after I moved into the scope of the delegate:

image

So, what was the problem? Basically it comes down to the scoping of Anonymous methods and how the compiler generates code to support them. Anonymous methods are simply compiler generated types. The generated type c__DisplayClass1 is not marked as serializable, so it fails when passed into the scope of the Anonymous delegate call…which is executing in another AppDomain (that does not contain the Anonymous type definition).

Tags: ,

Unit Testing

Jeff Morris

Tag cloud

Month List

Page List