3

I have a WPF application and a Silverlight application. They are both used to display a map and share some of the same functionality.

I have created a Silverlight class library project in order to stay DRY. I'm referencing this from both Silverlight and WPF. It contains some utility methods that are useful in both projects. For example, I have this method:

public static void CenterText(TextBlock name, Polygon poly)

The silverlight project has no problem with this. However, I get the following error when calling this from my WPF application:

The type 'System.Windows.Shapes.Polygon' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

However, I have this line at the top of the file:

using System.Windows.Shapes;

so WPF can see the Polygon class perfectly fine. My guess is that the silverlight class library uses a version of the framework which is not compatible with the version that the WPF project is using.

So the question is, am I stuck rewriting exactly the same code in my WPF application or is there some way I can share between the two?

Thanks!

H.B.
  • 166,899
  • 29
  • 327
  • 400
Erix
  • 7,059
  • 2
  • 35
  • 61

3 Answers3

5

You are right, Silverlight uses a completely separate version of the framework. It's much, much smaller than event the .NET client runtime.

This means you can't mix WPF and Silverlight assemblies in the same application.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
3

I ran into this error because I had downloaded the Expression Blend SDK for Silverlight instead of what I SHOULD have downloaded: Microsoft Expression Blend Software Development Kit (SDK) for .NET 4. It can be found on MSFT's website, here:

http://www.microsoft.com/en-us/download/details.aspx?id=10801

As soon as I downloaded the Expression Blend SDK for .Net, removed all of the Blend SDK for Silverlight references, and added those same references as Blend for .Net, I was up and running.

Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • +1 for the link and the info about different packages. I searched for the System.Windows.Interactivity dll and was pointed to the SL package when I didn't really want that one. – StingyJack Mar 20 '14 at 16:32
2

In Silverlight the class is in System.Windows.dll while in WPF it is in PresentationFramework.dll the library tries to get a hold of the Silverlight assembly which is not referenced by default in a WPF application.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • That makes sense. And it appears there is no System.Windows assembly to reference in .NET4 – Erix Jun 03 '11 at 21:19
  • Well, you can reference it if you get the dll from the respective folder, the problem is this won't work since both assemblies contain types with the same namespace and name so there would be conflicts. – H.B. Jun 03 '11 at 21:49