Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddObject chokes on List<T> #1062

Closed
ericnewton76 opened this issue Jan 1, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@ericnewton76
Copy link

commented Jan 1, 2018

Sample code:

	public class Person { public string Name { get; set; } }

	class Program
	{
		static void Main(string[] args)
		{
			var list = new List<Person>();
			list.Add(new Person { Name = "Joe" });
			list.Add(new Person { Name = "Mary" });

			var request = new RestRequest("url");
			request.AddObject(list);

			new RestClient("http://localhost:1234").Execute(request);
		}
	}

Expected Behavior

request.AddObject works without exception, just like request.AddObject(list.ToArray());

My suggestion is check if incoming object implements IEnumerable and start there with deciding how to serialize

Actual Behavior

request.AddObject(list); //crashes

Steps to Reproduce the Problem

  1. paste code
  2. run
  3. see exception

Specifications

  • Version:
  • Platform:
  • Subsystem:

StackTrace

System.Reflection.TargetParameterCountException occurred
  HResult=0x8002000E
  Message=Parameter count mismatch.
  Source=mscorlib
  StackTrace:
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at RestSharp.RestRequest.AddObject(Object obj, String[] includedProperties)
   at RestSharp.RestRequest.AddObject(Object obj)
   at ConsoleApp1.Program.Main(String[] args) in e:\temp\ConsoleApp1\Program.cs:line 21

@alexeyzimarev

This comment has been minimized.

Copy link
Member

commented Jan 1, 2018

You should not use AddObject for your scenario. Use AddJsonBody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.