I ran into the same old "cannot serialize value myType of type myType" issue the other day and knew immediately that I should check that my classes were marked with the [Serializable] attribute. Well, I checked and all of the classes had the attribute as required. So I spent an hour our so searching the web for other reasons why we might get this error. I found nothing.
So I pinged a buddy of mine and I walked him through the issue. He said, "It's gotta be one of your classes missing the Serializable attribute. Did you try writing a test to the serialization?" For some reason I was avoiding writing this test, but I broke down and did it.
This is what I found. You must be careful what classes you use to implement IEnumerable<T>. List<T> will serialize okay, but there are others that will not. In particular, my problem was with Enumerable<SelectIterator>. It isn't marked serializable. Where does this SelectIterator come from? The Select extension method:
ids.Split( ',' ).Select( id => new Deal { Id = int.Parse( id ) } )
Of course there was a simple fix.
ids.Split( ',' ).Select( id => new Deal { Id = int.Parse( id ) } ).ToList()
The good news is now I have a test so if I forget why the ToList is there and remove it, my test will fail. The next time I get an error, I will do the right thing... write a test to reproduce it.