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

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

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

If editing had a second argument with a null value.

Why is this?

+86
c # asp.net-mvc-3
Sep 13 '12 at 19:39
source share
2 answers

The underlying expression tree API does not support optional arguments.

For IL-compiled code, the C # compiler inserts default values ​​at compile time (hard-coded) because the CLR does not support calls with optional arguments when the arguments are not explicitly specified.

+74
Sep 13 '12 at 19:55
source share

There was the same message when trying to use Mock.setup for a method layout with several default parameters. I just needed to add additional parameters to the lambda.

 void someMethod(string arg1 = "", string arg2 = "") mockedObject.Setup(x => x.someMethod(It.IsAny<string>(), It.IsAny<string>())) 
+57
11 Oct '17 at 13:13
source share



All Articles