This is my mistake, [assembly: Obfuscation(Feature = "renaming", Exclude = false)] should not be used.
-----------------
Compiled exe get Exception:
(Release Configuration, Renaming is enabled.)
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “45BF23BC.E92BD6B0” does not contain a definition for “InvokeDynamicMethod”
CallSite.Target(Closure , CallSite , Type , Object , String )
System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
---
8E39D630.62302C06()
8E39D630.C0149A0C(Object A694F621, Int32 9F348F37)
8E39D630.2D8981A5()
8E39D630.C0149A0C(Object A694F621, Int32 9F348F37)
---
8E39D630.62302C06()
8E39D630.C0149A0C(Object A694F621, Int32 9F348F37)
6DB833A2.2A373C13()
Code: Select all
[Obfuscation(Feature = "ultra", Exclude = false)]
public static void test()
{
dynamic dynamicObject = new ExpandoObject();
dynamicObject.SayHello = new Func<string>(() => "Hello from dynamic method!");
string result = InvokeDynamicMethod<string>(dynamicObject, "SayHello");
Console.WriteLine(result);
}
[Obfuscation(Feature ="ultra",Exclude =true)]
private static T InvokeDynamicMethod<T>(dynamic obj, string methodName)
{
var binder = Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(
Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags.None, methodName,
null, obj.GetType(),
new[] { Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(
Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags.None, null)
});
var callSite = CallSite<Func<CallSite, object, object>>.Create(binder);
return (T)callSite.Target(callSite, obj);
}