Erix
Erix

Reputation: 7105

Errors when referencing Silverlight class library from WPF application

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!

Upvotes: 3

Views: 4852

Answers (3)

Lynn Crumbling
Lynn Crumbling

Reputation: 13357

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.

Upvotes: 3

ChrisF
ChrisF

Reputation: 137138

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.

Upvotes: 5

brunnerh
brunnerh

Reputation: 184451

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.

Upvotes: 2

Related Questions