C# – An expression tree may not contain a call or invocation that uses optional arguments

asp.net-mvc-3c

An expression tree may not contain a call or invocation that uses
optional arguments

return this.RedirectToAction<MerchantController>(x => x.Edit(merchantId));

Where edit had a second, nullable argument.

Why is this?

Best Answer

Had the same message when trying to use Mock.setup to mock a method with multiple default parameters. I just had to add the additional parameters in the lambda.

void someMethod(string arg1 = "", string arg2 = "")

mockedObject.Setup(x => x.someMethod(It.IsAny<string>(), It.IsAny<string>()))
Related Topic