views:

98

answers:

3

I have a simple Silverlight app that I want to run on Windows Phone 7 almost exactly as is. I've created a new Windows Phone 7 project and when I reference the Silverlight app I get a warning that says "Adding a reference to a Silverlight project might not work properly. Do you want to continue?".

If I continue and try to run anyway, the WP7 project never starts or sometimes I get "AG_E_PARSER_BAD_TYPE error" and it points to the line in the xaml I used a control from the Silverlight project .

The code between these two projects is about 99% the same. Is there another way to reuse code then what I am trying? Or how can I get this to work?

+4  A: 

I'm not that familiar with the difference between the two platforms, but you can link the code files into a different project without duplicating them. Add existing item, and click on the down arrow next to the 'Add' or OK button. Choose Link.

StephaneT
Benjamin Baumann
+1 - cool, didn't know about that
StephaneT
This didn't occur to me but I suppose it could work. But I have to do it to every dependency as well and I don't have the source code for all of them.
liserdarts
A: 

The typical way of achieving this is by using a pattern like MVVM which will allow you to define a common model and viewmodel layer (perhaps in a separate project) the defining a different view layer that references that common project.

You said it yourself, you will only share MOST of the code, not all of it, so you will, at least at some time, need to create device/front-end specific logic and layout.

Mark
This doesn't avoid the issue because the common project would either have to be a Silverlight project (and not work with wp7) or a wp7 project (and not work with Silverlight).
liserdarts
You can still do this though, Silverlight for WP7 is based on SL3, so unless you have desktop specific code in your common library, your all good
Mark
See here: http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/79858a29-4db0-460d-9a75-3630211a28fb/
Mark
Thanks, the information in that post is what I needed. I'm finding the source of "AG_E_PARSER_BAD_TYPE error" using divide and conquer.
liserdarts
+1  A: 

Rather than add a Silverlight [presumably class library] project to your WP7 app, try creating a WP7 class library and then link the files from the silverlight library. You will still only have one copy of each file but all your libraries will be built appropraitely for the platform they are running on.

This may also help you identify the cause of the problem. The error AG_E_PARSER_BAD_TYPE suggests that you have a type in the XAML in your Silverlight project which isn't supported on the phone.

Matt Lacey