question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No parameterless constructor defined for this object on arrays & enumerables of simple types

See original GitHub issue

The following error is thrown when Execute<T>() is called with T having string[], IEnumerable<T> and similar.

This seems rather easy to fix on the JsonDeserializer, I wonder if it wasn’t done on purpose?

Let me know if I should send a PR with a fix

System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at RestSharp.Deserializers.JsonDeserializer.CreateAndMap(Type type, Object element)
   at RestSharp.Deserializers.JsonDeserializer.ConvertValue(Type type, Object value)
   at RestSharp.Deserializers.JsonDeserializer.Map(Object target, IDictionary`2 data)
   at RestSharp.Deserializers.JsonDeserializer.CreateAndMap(Type type, Object element)
   at RestSharp.Deserializers.JsonDeserializer.ConvertValue(Type type, Object value)
   at RestSharp.Deserializers.JsonDeserializer.Map(Object target, IDictionary`2 data)
   at RestSharp.Deserializers.JsonDeserializer.CreateAndMap(Type type, Object element)
   at RestSharp.Deserializers.JsonDeserializer.ConvertValue(Type type, Object value)
   at RestSharp.Deserializers.JsonDeserializer.BuildList(Type type, Object parent)
   at RestSharp.Deserializers.JsonDeserializer.ConvertValue(Type type, Object value)
   at RestSharp.Deserializers.JsonDeserializer.Map(Object target, IDictionary`2 data)
   at RestSharp.Deserializers.JsonDeserializer.CreateAndMap(Type type, Object element)
   at RestSharp.Deserializers.JsonDeserializer.ConvertValue(Type type, Object value)
   at RestSharp.Deserializers.JsonDeserializer.Map(Object target, IDictionary`2 data)
   at RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response)
   at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

17reactions
nadirakdagcommented, Jan 3, 2015

this error about arrays if you convert your arrays to list you can escape this error. First version public object[] sizes { get; set; }

Right version public List<object> sizes { get; set; }

11reactions
urigcommented, Sep 9, 2015

+1 for including this feature in the built-in JSON deserializer.

Deserializing arrays is a basic scenario for consuming REST APIs. IMHO RestSharp users, especially inexperienced ones, should not have to invest effort in custom serialization for something so trivial.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No parameterless constructor defined for type of 'System. ...
I'm getting this error 'No parameterless constructor defined for type of 'System.String' during JSON deserialization' when I try to call my C# ...
Read more >
Parameterless struct constructors - C# 10.0 draft feature ...
The implicitly-defined parameterless constructor will zero fields rather than calling any parameterless constructors for the field types. No ...
Read more >
Activator.CreateInstance Method (System)
Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the specified parameters....
Read more >
Error: No parameterless constructor defined for this object
Obviously it happens because somewhere a class expects to be able to use dependency injection through it's constructor like this:
Read more >
C# Constructor (With Examples)
A constructor in C# is similar to a method that is invoked when an object of the class ... without parameters, it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found