Once in a while, I create a web service using WCF and attempt to create a service reference to it from my Silverlight client application.
Most of the time, my Silverlight app compiles fine and the generated service proxy client code is indeed correct. However, there are times when certain operations on my service contract generate methods decorated with the attribute: [System.ServiceModel.ServiceKnownTypeAttribute(typeof(System.MarshalByRefObject))] – an unsupported attribute in Silverlight.
In fact, a colleague of mine also had exactly the same problem, and after scouring the web, both of us came up empty. Therefore, I decided to write a quick blog post about this strange and rather annoying issue.
Of course, you could just erase/comment out this line and rebuild your service proxy in Silverlight, but remember, that every time that the proxy is updated, your compilation will fail until you have removed any reference to MarshalByRefObject from your code.
First, check if you have any of these attributes listed as well (on the same method as System.MarshalByRefObject):
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(byte[]))]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(MemoryStream))]
Most likely, your method is referencing, either directly or indirectly, a MemoryStream type, and Silverlight is trying to figure out how it is going to serialize/deserialize it. You need to do a little bit of detective work to find out exactly which type (and property on that type) is the culprit, by checking your service code.
When you find the culprit, you need to change the type of the property to a type that Silverlight can readily serialize/deserialize, or avoid serializing that property altogether.
Disclaimer: I don’t know why Silverlight generates a System.MarshalByRefObject reference for the client service proxy since it does not support it anyway. Perhaps we can forward this question to the Silverlight team.
Hope this helps.