views:

436

answers:

3

Hey there,

I am writing a Large Scale Silverlight Application. I am currently writing the data retrieval elements.

I have now encoutered and issue.

I have a common Project that hold objects, this project is referenced by both the UI and the WCF service. The UI requires INotifyPropertyChanged for binding purposes.

Now the WCF must use the same objects, but I am getting a compiler error saying

"The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced."

EDIT: The error is in the WCF service.

I want one object class, how do I solve this problem?

diagram

Thanks -Oliver

A: 

did you add a reference in the compiling project to System.ComponentModel

rerun
+1  A: 

If you plan to use the same source code for your Entities (domain) for both a clr and silverlight project you will need to use 2 projects because the Silverlight assemblies are not the same as CLR assemblies.

Add a Silverlight Class Library project to your solution, the name is not important but I usually just use XXXX_SL.

Now, you will 'Add Existing Item' all of the source files from the clr project, but notice the dropdown on the open or select button? click that and 'add as link' or whatever it says there.

You are now using the same source for both projects and your solution will compile.

There may be some minor tweaks along the way but that will set you on the right path..

Here is some reference material

Sky Sanders
Sorry, I forgot to mention that the error happens when compiling the WCF service.Edited first post
Oliver
@Oliver: well System.ComponentModel.INotifyPropertyChanged lives in System (mscorlib.dll) so... you should in the off chance that there is not a reference to System, add it. that would be strange but can happen.
Sky Sanders
I have added the System.ComponentModel using statement and the problem still persists. This is why I posted because it doesn't seem right and I was wondering if I was missing something.
Oliver
The service has the System.ComponentModel using statement, the class allows me to see the INotifyPropertyChanged interface but I still cannot compile:'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
Oliver
@Oliver: note how it looks for version 2.0.5.0. That's the Silverlight version. The normal .NET version is 2.0.0.0.
John Saunders
@John so what would be the solution? I have been reading this http://www.netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight. Can I use mscorlib 2.0.0.0 in the the silverlight class library to "bypass" this issue?
Oliver
@oliver - I answered your question with a big bold link. I am not guessing. This is how you share source code between clr and silverlight projects. I have done it. repeatedly. with success.
Sky Sanders
@Oliver: the solution is to listen to what @Sky says: he's done this before. I'm just pointing out the version difference.
John Saunders
Wasn't doubting your advice Sky, it is appreciated.I have a new question, your method works nicely for INotifyPropertyChanged but now how do I add ObservableCollection to the CLR Model?
Oliver
Add a reference to WindowsBase.dll - c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll
Sky Sanders
That solves the referencing issue in the CLR Model but the WCF Service that is using that model now won't host stating this error:Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies.This is a Silverlight reference. How do I solve this?
Oliver
On the wcf side you should only use your clr model, and it should have no silverlight references. The conversion is implicit, the silverlight serializer will automagically convert the json to your silverlight model.
Sky Sanders
Ok sorry, VS was just playing up. I deleted the Model reference and re-added it and it is happy.THANKS SO MUCH!
Oliver
Glad it worked out. You may keep in mind that the solution 'Clean' operation is quite useful in situations where references seem muddled.
Sky Sanders
The link at the end of the post is great!
Eric J.
A: 

I found a method here that allows one to create the CLR classes on the service side and then one can use the generated objects from the Service Reference as the classes are generated with the INotifyPropertyChanged and ObservableCollection.

This solves the immediate problem of the client/server boundary but does fit into my solution because in order to use the generated objects you need the service reference. But I have a ProxyClass that does the talking to WCF so there I cannot see a way of passing these object types back to the ViewModel.

I see some people have written mapper classes, but this is far from ideal as I would have to write 3 classes for each POCO object (client class, server DTO class, mapper).

Any more suggestions?

Oliver