0

I was receiving a "cannot serialize type..." error while attempting to serialize a BindingList. My initial thought was that the collection was the problem. I bypassed the collection and attempted to return a single instance of the class...same error. The classes are contained in a seperate project (but in the same solution); my next move was to copy and paste the class from the external project into the WCF project. With no other changes, the object now serializes.

Is this a namespace or persmissions issue? I can't rearchitect the solution at this point. What would prevent the class from seralizing in another project with the same code? Thanks in advance.

m0r6aN
  • 850
  • 1
  • 11
  • 19
  • Can you post the full exception details (i.e. exception.ToString())please? – Drew Marsh Aug 19 '11 at 15:59
  • 1
    Did you add the Serializable attribute to the class? Still doesn't explain why it worked when you ported it over, but I'm curious. – James Johnson Aug 19 '11 at 16:01
  • When I was returning a BindingList of objects, my BindingList was marked as Serializable `[Serializable] public class BindingListBase : BindingList` The individual class (before and after moving) is marked as ` [DataContractAttribute] [DataContractAttribute] public class ICAddress : INotifyPropertyChanged, IObject ` – m0r6aN Aug 19 '11 at 16:35

2 Answers2

0

Often when we get this error there is a sub class that does not have the Serializable or DataContract / DataMember attribute.

What is the class that you are using as T? Is that class marked as serializable?

Edit

For the error in the comment see "An attempt was made to load a program with an incorrect format" even when the platforms are the same

Community
  • 1
  • 1
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • No, it wasn't. It was just marked as [DataContractAttribute]. But it works as so when ported; standalone and as part of a BindingList collection. I noticed that my references were assembly refs so I blew them away and re-added them as project references. Now I get the message "An attempt was made to load a program with an incorrect format". Everything is set to compile to 64bit. – m0r6aN Aug 19 '11 at 17:49
  • Everything is building to 64 bit. I blew away the bin and obj folders for all projects and rebuilt. All IIS app pools are set to allow 32 bit applications. Same error... – m0r6aN Aug 19 '11 at 18:30
0

The fix for this was to simply recreate the WCF solution and add the class library projects to it. I have no idea what the problem was. Maybe bad meta information or something.

m0r6aN
  • 850
  • 1
  • 11
  • 19