When repassing a dynamic parameter to a method with params keyword the solution fails to build, I am using .NET 4.6 and VS2015, but the problem also happens with previous versions of .NET Framework. No error is produced on Error List, just a "Build Failed" message at the bottom.
This is the sample code I am trying to run:
public void MethodWithDynamicParameter(dynamic dyn)
{
MethodWithParams(dyn); //This fails to build!
MethodWithParams(new object[] { dyn }); //This compiles!
}
public void MethodWithParams(params object[] objects)
{
}
Can someone explain what is wrong with the first call?
EDIT 1:
I´ve created a new solution with the sample provided by Dave and it builds with no problems. But in my solution the problems persists even after "Close, clean and build". It does not matter if I pass a string, a object, a dynamic or anythin else. At the image below there are no calls to method and the solution still does not build.
I have created a new Console Application using the following code as a test:
For me, the program both compiles and runs without error.
May I suggest the standard "close all documents, clean all, rebuild all" and/or "restart Visual Studio" solutions, if you have not yet attempted this?
Additionally, they
dynamic
keyword might be the source of your troubles, as it bypasses many of the typing checks until compile time. Try checking your code from wheredyn
would be declared, prior to making the call toMethodWithDynamicParameter(dynamic dyn)
.