Binding exception with dynamic keyword in c#

2019-07-31 03:28发布

I am loading my assemblies at run time and I am also using Instance Activator to get the code at the runtime. Following code will summerize what I am doing:

dynamic powerTool;
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(
    @"C:\Users\c_desaik\Desktop\PowerTool.exe");
Type type = assembly.GetType("PowerTool.Automation");
powerTool = Activator.CreateInstance(type);    

Now, as you have noticed, Powertool has been declared as dynamic because I do not want my code to fail at Compile time and I want it to resolve all the operations at the Runtime.

While I do that the code fails to execute down the line with the following error:

An unexpected exception occurred while binding a dynamic operation

Now I thought that the entire concept behind the dynamic keyword was to be abl eto resove all the members and operation at the run time. How can I resolve this error?

0条回答
登录 后发表回答