Print Page | Close Window

'System.Reflection.RuntimeMethodInfo' cannot be serialized

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
Printed Date: 17-Dec-2018 at 10:07am

Topic: 'System.Reflection.RuntimeMethodInfo' cannot be serialized
Posted By: ahopper
Subject: 'System.Reflection.RuntimeMethodInfo' cannot be serialized
Date Posted: 18-Mar-2010 at 9:22am
We are trying to use the fluent interface to generate a Linq query that applies a where clause:
em.ExecuteQueryAsync<Principal>(em.Principals.Where(p => p.DisplayName == "ahopper"), this.QueryExecuted, null);
However, when the callback is invoked, it has an error:

“Type 'System.Reflection.RuntimeMethodInfo' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.”

Are we simply using the API incorrectly?
Many thanks!
Andy Hopper
Enterprise Architect, Wintellect -

Posted By: ting
Date Posted: 18-Mar-2010 at 12:53pm
Hi Andy,
A)  If Principal is a POCO class you should do these things:
  1. Mark the class with the [DiscoverableType(DiscoverableTypeMode.KnownType)] attribute or have the class implement IKnownType (a marker interface).
  2. Mark each property with the [DataMember] attribute.
For example:
    public class Principal {
      public String DisplayName {
        get { ... }
        set { ... }
B)  If Principal is a standard DevForce Entity, you can only issue queries to the database on properties that are backed by database columns.  If DisplayName is a calculated or custom property, the database engine doesn't know what to do with it.  Once you have brought down the object into the client-side cache, however, you can use LINQ-to-objects to query on any arbitrary property.
If you're still having problems, send us the edmx file and we'll have a look.
Good luck!

Posted By: ahopper
Date Posted: 18-Mar-2010 at 3:29pm
Hi, Ting! Yes, these are EF classes, and DisplayName is bound to a database field. To what address should I send the edmx file?

Posted By: ahopper
Date Posted: 19-Mar-2010 at 1:22pm

Aha! We found it. Our client-side app.config did not have the clientApplicationType attribute set to “Silverlight” and this appears to break the code that serializes the Where clause.

Print Page | Close Window