c# - Why repassing dynamic parameter to params parameter fails to build -
when repassing dynamic parameter method params keyword solution fails build, using .net 4.6 , vs2015, problem happens previous versions of .net framework. no error produced on error list, "build failed" message @ bottom.
this sample code trying run:
public void methodwithdynamicparameter(dynamic dyn) { methodwithparams(dyn); //this fails build! methodwithparams(new object[] { dyn }); //this compiles! } public void methodwithparams(params object[] objects) { } can explain wrong first call?
edit 1:
i´ve created new solution sample provided dave , builds no problems. in solution problems persists after "close, clean , build". not matter if pass string, object, dynamic or anythin else. @ image below there no calls method , solution still not build.
i have created new console application using following code test:
class program { static void main(string[] args) { // test object: object x = new object(); methodwithdynamicparameter(x); // test specific type of object, string: methodwithdynamicparameter("string"); console.readkey(); } static void methodwithdynamicparameter(dynamic dyn) { methodwithparams(dyn); methodwithparams(new object[] { dyn }); } static void methodwithparams(params object[] objects) { } } for me, program both compiles , runs without error.
may suggest standard "close documents, clean all, rebuild all" and/or "restart visual studio" solutions, if have not yet attempted this?
additionally, dynamic keyword might source of troubles, bypasses many of typing checks until compile time. try checking code dyn declared, prior making call methodwithdynamicparameter(dynamic dyn).

Comments
Post a Comment