Automapper and Silverlight 4? Yes Please!
January 16, 2011 2 Comments
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:
- File-New Project/New Silverlight Application. Call it Automapper.Silverlight4.
- Copy the “lib” folder from the Automapper source into the root folder of your new build
- Add Reference to Castle.Core and Castle.DynamicProxy2 from the lib folder (don’t worry about the net3.5 folder, still works)
- Right-click the project and select Add Existing Item
- Navigate to the Automapper source and select all files in the root, then select Add As Link from the dropdown.
- Create Internal and Mappers folders and repeat the above steps for those folders in the Automapper source project.
- Delete links to DataReaderMapper and ListSourceMapper under Mappers folder (not supported by Silverlight.)
- 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.
Hello Dave, could you provide a compiled dll? I tried the process you said and it did not work.
Sorry Jefferson, I don’t have that code anymore. Did it not compile?