Automapper and Silverlight 4? Yes Please!

I’m working on a fairly complex Silverlight application (Entity Framework 4, Prism/Unity, WCF RIA Services) and suddenly ran head-first into a need for some object mapping.  I haven’t done this before, but I had heard of Automapper so I Googled it and read the documentation.  Perfect!

Then I read up on the Silverlight Automapper release.  Uh-oh… last built in February 2010.  For Silverlight 3.  Curses…

I had two options at this point.  Do my mapping at the server side using the “regular” Automapper, or dig in and make Automapper Silverlight Edition work for me.  I downloaded the source, thinking I could (as I had done before with other projects) simply change the compilation target to Silverlight 4 and recompile.  Tried this and BAM!  No worky.  The version of mscorlib is 2.0.

Tried removing mscorlib and re-adding it from the Reference Assemblies.  BAM!  Visual Studio bug.

OK, so this will have to be a new project:

  1. File-New Project/New Silverlight Application.  Call it Automapper.Silverlight4.
  2. Copy the “lib” folder from the Automapper source into the root folder of your new build
  3. Add Reference to Castle.Core and Castle.DynamicProxy2 from the lib folder (don’t worry about the net3.5 folder, still works)
  4. Right-click the project and select Add Existing Item
  5. Navigate to the Automapper source and select all files in the root, then select Add As Link from the dropdown.
  6. Create Internal and Mappers folders and repeat the above steps for those folders in the Automapper source project.
  7. Delete links to DataReaderMapper and ListSourceMapper under Mappers folder (not supported by Silverlight.)
  8. Build!

It works!  I now have Automapper working in a Silverlight 4 application.  I’m sure I’m not the first to try this, but it’s good to know it’s possible.

About these ads

2 Comments on “Automapper and Silverlight 4? Yes Please!”

  1. Hello Dave, could you provide a compiled dll? I tried the process you said and it did not work.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.