No parameterless constructor defined for this object on arrays & enumerables of simple types
See original GitHub issueThe 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:
- Created 9 years ago
- Comments:16 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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; }
+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.