0
votes

I have a silverlight 4 project that uses wcf ria services to connect to the server. I have a public class that I need to use on both the client (silverlight) and server. What is the best way to accomplish this?

I have tried using the .shared.cs file convention on the server as well as a linked file (original is on the server). The client thought there was a duplicate class so I changed it to a partial class (I would prefer not to). Then it complained about duplicate properties so I tried the solution to this stack overflow question. The problem I run into using this solution is not being able to access my enumerations that are in the original class on the server.

I also tried a creating a class library project that both of the other projects could reference (silverlight client and server). The problem is finding a type of project to create that both of the projects can reference. Silverlight complains about non silverlight projects and vice versa.

3
I've used linked files a lot, and they've worked fine. Is there a technical reason for you not to use them?Andrew
I've tried using them but they don't allow me to use my enums located in the shared cs file in the silverlight projectBen

3 Answers

0
votes

Have you considered using the Portable Library Extension tools.

To quote from here, the Portable Class Library project enables you to write and build managed assemblies that work on more than one .NET Framework platform.

0
votes

I think the best solution here would be to create a new project in a solution (you may call it Helpers, Common, etc) and add a reference in both client and server projects. That way you will use the same class in both of them and if you change the structure of a class it will affect both projects.

0
votes

I'm not sure about where your problem came from (what do you mean by not being able to access your enumerations ?) however you may find useful to know that .NET supports a feature called assembly sharing that is meant to share some basic type across silverlight and .net. Just keep in mind that you should reference the Silverlight assembly, not the silverlight project. If this break your compilation order, add also a "fake" project reference into your csproj file like this:

<ProjectReference Include="..\MySilverlightSharedProject.csproj">
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>

as documented here