No parameterless constructor defined for an imported object type to be deserialized from JSON

215 Views Asked by At
Dim result = New JavaScriptSerializer().Deserialize(Of SearchResult)(Request.Cookies.Get("user").Value)

An exception of type 'System.MissingMethodException' occurred in System.Web.Extensions.dll but was not handled in user code

Additional information: No parameterless constructor defined for type of 'System.DirectoryServices.SearchResult'.

I see there have been many questions regarding this issue, but the required object types were self-defined class, so the solution would be to create a new and parameterless constructor for that class.

In my case, I am trying to use SearchResult from namespace System.DirectoryServices as the object type to be deserialized from JSON String. How can I solve it?

1

There are 1 best solutions below

0
Stephen Kennedy On

You can't deserialise a SearchResult object because it has no public constructor.

In theory you could write a JavaScriptConverter and use reflection to instantiate an instance of the target class in the convertor's Deserialize() method but that would be hackery of the first order.

Either serialize and deserialize a custom class of your own making, or rethink what you're doing.