[英]Casting dynamic to ObjectHandle throws RuntimeBinderException
I'm trying to determine the type of a dynamic at run-time using the much publicized way of Type obtainedObjectType = ((ObjectHandle)obtainedDynamicObject).Unwrap().GetType();
我正在尝试使用广为人知的
Type obtainedObjectType = ((ObjectHandle)obtainedDynamicObject).Unwrap().GetType();
来确定运行时动态Type obtainedObjectType = ((ObjectHandle)obtainedDynamicObject).Unwrap().GetType();
but am getting a RuntimeBinderException for the ObjectHandle casting and I don't know why. 但是正在为ObjectHandle转换获取RuntimeBinderException,我不知道为什么。
The following also throws the same error; 以下也引发相同的错误;
string myString = "ASF";
dynamic myDynamic = myString;
ObjectHandle dd = (ObjectHandle)myDynamic;
Throws: "Cannot convert type 'string' to 'System.Runtime.Remoting.ObjectHandle' 抛出:“无法将类型'string'转换为'System.Runtime.Remoting.ObjectHandle'
Odd thing is that I've used it at my last workplace and it was fine! 奇怪的是,我在上一个工作场所使用过它,很好! Using .NET framework 4.5 (and tried with later).
使用.NET Framework 4.5(并在以后进行尝试)。 Any ideas?
有任何想法吗?
Why to go a complicated way!? 为什么要走复杂的路! Just do:
做就是了:
Type myDynamicType = myDynamic.GetType();
Console.WriteLine(myDynamicType); // Output is System.String
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.