Skip to main content

Microsoft Silverlight

Answered Question Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?RSS Feed

(0)

xsirxx
xsirxx

Member

Member

28 points

40 Posts

Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

Hi everyone, first time poster here!  Just wanted to say thanks in advance for any help!

 Ok here is my problem.  I have a Silverlight 2.0 beta 1 project and have a website project, a silverlight application project, and a silverlight control library project all in my solution.  When I create a WCF service under my web site project everything runs fine.  Now If I create a custom object with the DataContract and DataMember attributes under the website and use it as an input value to a WCF call it still runs fine.  Now If I create a custom object under my silverlight control library and use it as an input into the WCF service it bombs out with this error:

 

Could not load file or assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

 

I cant seem to get around this issue.  I would like to have my business objects seperated out from the website and under their own library but I cant seem to serialize the objects this way.  Also I cant find what version of System.Runtime.Serialization is contained in System.Web.Silverlight.dll if indeed this is where it is located.  Although building a silverlight website the old way, I see System.Runtime.Serialization to be of version 3.0.0 when the library is only allowed version 2.0.5.0.

I also cannot find a way to force 3.0.0 of System.Runtime.Serialization in my silverlight control library, it uses 2.0.5.0.

 

Any help would be greatly appreciated!

 

Thanks,

Brad 


 

Jabb
Jabb

Member

Member

462 points

81 Posts

Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

 

First off, the base Silverlight assemblies are installed at

C:\Program Files\Microsoft Silverlight\2.0.30226.2 

You will find the Silverlight System.Runtime.Serialization.dll in the above directory. 

These assemblies are designed to run on the Silverlight CLR; you cannot mix assemblies from the .NET Framework and the Silverlight Framework, which means you cannot share assemblies across the two frameworks. 

  

xsirxx
xsirxx

Member

Member

28 points

40 Posts

Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

That is interesting because when I start a new project(using the selection Web Site on the second menu), it starts 2 projects in one solution for me.  The Website and the silverlight application.  The website uses System.Web.Silverlight.dll "C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Libraries\Server\".  The application uses c:\Program Files (x86)\Microsoft Silverlight\2.0.30226.2\System.Runtime.Serialization.dll.  The problem is the website is using what I believe is .NET 3.0 System.Runtime.Serialization while the silverlight application project is using 2.0.5.0.  I cannot add the reference of "C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Libraries\Server\System.Runtime.Serialization.dll" into the website project

This difference is what I believe is causing all these issues.  I can take the EXACT class and move it into my Website project and it runs absolutely fine. It is only after I call the DataContractSerializer that it bombs.

Hope this helps any misunderstandings, sorry about that.

 -Brad

Jabb
Jabb

Member

Member

462 points

81 Posts

Re: Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

The System.Web.Silverlight.dll assembly is a .NET 2.0 server-side assembly containing, among other things, the SilverlightPlugin class that your ASPX uses to render the HTML Silverlight plugin code.

So yes, the website that the Silverlight Application template targets the .NET Framework, while the actual Silverlight Application targets the Silverlight Framework.

xsirxx
xsirxx

Member

Member

28 points

40 Posts

Re: Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

I cant manage to get any type of serializing to work on my WCF server.  I try to use XmlSerializer to deserialize on the WCF server side(Service Contract) but it says it cannot find System.Xml.Serialization 2.0.5.0.  So I include it by selecting "Copy Local", and it says that it is already included in another location at runtime and bombs.  So I try to push the deserialization function on the actual object itself but it bombs this time without an actual exception.  The string looks correct that is being sent over.

 So I ask this, if anyone can help me by trying a few things out I would GREATLY appreciate it.

Would someone be willing to test a new project created with the Silverlight Application template, and on the second option select Website.  Create a FooBar  object with just one field under the application side and either try to serialize it with a DataContract or on your own with XmlSerializer.  Then create a WCF Service on the Website project and make reference to it.  Now try to use the input parameter in your WCF function as the FooBar object.  Run a Async command to the service.

I cant seem to get this to deserialize on the WCF server side.  Matter of fact I cant seem to get ANY custom object whatsoever to deserialize on the server side.  Now understand I can use any built-ins just fine ie.(String, int, bool, byte...).

 

Again I would greatly appreciate any help whatsoever, as I have been working on getting serialization working under WCF for a couple of weeks.

 Thanks again,

Brad

 

xsirxx
xsirxx

Member

Member

28 points

40 Posts

Re: Re: Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

BTW I just wanted to throw an update out there that if I create another porject in my solution as a Class Library, it wont work and gets the same error not being able to find Serialzation library of 2.0.5.0.  BUT, if I switch out the Serialzation dll out of my class library for the 3.0.0 version then it runs perfect.  Only problem now of course is a silverlight application cannot use class library classes because they arent built under silverlight.  So I have to use a reference to the library through Add Web Service....

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: Re: Re: Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

Hello, try those steps:

Optional: These steps only needs to be done if you want to put your business object classes in a separate assembly.

  • Create a Class Library which uses full CLR (not a Silverlight Class Library).
  • In the Class Library project, add a reference to full CLR version's System.Runtime.Serialization.dll (3.0.0.0).
  • Create your business classes and mark them as DataContract/DataMember.
  • In your web site application, add a reference to your Class Library.

Required: These steps are required.

  • Create a WCF service in the web site application. This service will probably use your business objects.
  • Build the WCF service. Make sure it compiles fine.
  • In your Silverlight application, add a service reference to the WCF service. This will create a proxy for you. This proxy includes all the dirty works dealing with channels, and will generate a Silverlight version of your business classes. Note you can't reference to your Class Library directly from your Silverlight application. They're incompatible. The business classes should be generated automatically by the proxy.
  • Call the service as normal. Your application should run fine.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

russau
russau

Member

Member

10 points

23 Posts

Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

hi, did you have any luck with this?  it seems the wcf service wants the DataContract / DataMember attributes.  when you add these attributes to a silverlight library class you are using the attributes from the silverlight System.Runtime.Serialization.dll (2.0.5.0).  which the wcf service doesn't recnogise.

it appears this problem goes away in .net 3.5 sp1 - http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/13/50934.aspx

russ

 

xsirxx
xsirxx

Member

Member

28 points

40 Posts

Re: Silverlight 2.0 beta 1, System.Runtime.Serialization. Bombing on custom object?

 I have found ways around it but yes 3.5 SP1 helped greatly.... I have gone that route for serializing through WCF.  For Sockets I simply copy my code over for packet classes that are being serialized then mark the attributes the same on those....  Its redundant but it works.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities