Click here to Skip to main content
13,894,020 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 19 Nov 2009
Licenced CPOL

Silverlight 3 & 4 Library Sharing with .NET 4.0 Library or WPF

, 19 Nov 2009
Rate this:
Please Sign up or sign in to vote.
Silverlight 3 & 4 library sharing with .NET 4.0 library or WPF


As if you need “another” reason to start running Visual Studio 2010 Beta 2, here is another for all the cross platform .NET Line of Business application developers.

Silverlight 3 & 4 Library assemblies can be referenced in .NET 4.0 applications and used.

The above WPF application has a file reference also known as a binary reference (as opposed to a project reference) to the BusinessEntities.Silverlight.dll and has instantiated the Customer class and used it for the DataContext for the above MainWindow.

How To Do It

The steps are simple, but you need to follow the workflow to avoid issues.

Now that Silverlight 4 has shipped and IDataErrorInfo has been added, this enables entity sharing between Silverlight and WPF much easier since you no longer have to implement this interface yourself just to get code compatibility with your business objects.


  1. Your Silverlight Library can't have any “Silverlight specific” code in it. I have been able to share my own framework code (Ocean) and business entities without any issues.
  2. Set up a file reference (as opposed to a project reference) between the .NET 4.0 project and your Silverlight 3 or 4 class library .dll. In the add reference dialog, use the Browse button to locate the target .dll.
  3. If you have the Silverlight 3 or 4 library in the same solution as the consuming .NET 4.0 project(s), it is important that you establish the correct project dependencies and build order. By default, Visual Studio will not alter your project build order when a file reference is made.

    In our case, we need the project build order to look like the below image:


    To establish the above build order, switch to the Dependencies tab, select the other solution projects that depend on the Silverlight 3 or 4 class library and check the Silverlight 3 or 4 library as pictured below:


A Few Thoughts

If you have never used file reference projects in your solution, a few things in the user experience are slightly different.


If you edit the Silverlight 3 or 4 class library, don't expect those changes to be picked up by the .NET 4.0 project(s) until after you build. This means, if you added a property or method in the code editor, IntelliSense in the .NET 4.0 project won't “list it” until you build the solution.

Build Order

It's easy to overlook manually setting the project dependencies to ensure the correct build order since for all other projects you have ever created, Visual Studio did this for you.

Also, don't overlook this step after adding a new project to an existing solution that you've already set the build order on.

Clean Solution

If you have the Silverlight 3 or 4 class library in the solution and you clean the solution, the library assembly .dll will be removed from the output folder. This will cause Visual Studio to add some errors to your Error List since it can no long find the referenced assembly. After building the solution, these errors will be removed from the Error List.

So… if you clean your solution and send it to someone like on a blog post, developers that open your solution will see these errors. Again, build and all is well.

Service References

Now that you can put your business entities in a Silverlight 3 or 4 class library and your .NET 4.0 service, business and data layers can consume those entities, take full advantage of service reference dialog Advanced settings. Advanced button is located in the lower left corner of the Add Service Reference dialog.

I have had issues with the Add Service Reference feature when trying to get it to reuse my existing types. So I always elect to help the wizard and specifically select the assemblies that contain my business entities as I've done in the below image.

Note: The project download does not have a service reference, the below image is from another project.


I love this feature because it allows me to use my business entities that have code in them in all the layers of my application without any duplication of code. This also easily enables entity sharing between Silverlight 3 OR 4 and WPF.


The project source code can be downloaded from my SkyDrive.


Hope you like the new developer productivity capabilities of Visual Studio 2010.

Have a great day,

Just a grain of sand on the world's beaches.

Posted in CodeProject, Silverlight, VB.NET, Visual Studio 2010, WPF General


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Karl Shifflett
Architect Self
United States United States

I’m a passionate Platform Architect at Infragistics.

I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.

My front end passions are WPF, Electron, ES2015 (ES6), Node.js, and Angular.

For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.

I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.

My Blog

My Github Repros

Just a grain of sand on the worlds beaches.

You may also be interested in...


Comments and Discussions

QuestionAlso working with .NET 3.5? Pin
Tobias Norlund9-Oct-10 11:04
memberTobias Norlund9-Oct-10 11:04 
AnswerRe: Also working with .NET 3.5? Pin
Karl Shifflett11-Oct-10 3:09
memberKarl Shifflett11-Oct-10 3:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190306.1 | Last Updated 19 Nov 2009
Article Copyright 2009 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid