13

I am a newcomer to Silverlight and while I have been following some tutorials I wanted to create a new project with a class library so that I can use it from my page's xaml.cs code behind.

But when I tried to add my class library project I get a warning message saying:

You can only add project references to other Silverlight projects in the solution

It is clear what it says. But what is the reason behind this? Why I cannot add a class library project reference to a Silverlight project?

Thanks

pencilCake
  • 51,323
  • 85
  • 226
  • 363
  • 1
    Just to note: you can however link the other way (include Silverlight libraries in traditional .Net apps). This solves the problem of sometimes needing to share code between apps (usually business logic). – iCollect.it Ltd Sep 02 '10 at 13:14

2 Answers2

19

Instead of regular Class Library, you can use the "Silverlight Class Library" template. The reason why you can't use a regular Class Library is that the Common Language Runtime of Silverlight is different than the CLR of "regular" .NET Framework.

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
Mikael Koskinen
  • 12,306
  • 5
  • 48
  • 63
1

You can add a reference to a class library to a silverlight application but that class library needs to be a Silverlight Class Library.

When you use Add Project ont he solution select the "Silverlight" option under "Visual C#" ( or "Visual Basic" or even "Visual F#"). You will see a template for a "Silverlight Class Library". Your class library needs to have used this template in order to be eligable to be reference by a Silverlight application or other Silverlight Class libraries.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306