小编Jam*_*mes的帖子

无效的转换异常:无法将类型“__DynamicallyInvokableAttribute”的对象转换为类型“BugFixApplication.DeBugInfo”

我尝试将 Attribute 变量类型转换为 DeBugInfo 类型。

这是类 ExecuteRectangle 中 Main 函数的代码:

class ExecuteRectangle
{
    static void Main(string[] args)
    {
        Rectangle r = new Rectangle(4.5, 7.5);
        r.Display();
        Type type = typeof(Rectangle);
        //iterating through the attribtues of the Rectangle class
        foreach (Object attributes in type.GetCustomAttributes(false))
        {
            DeBugInfo dbi = (DeBugInfo)attributes;
            if (null != dbi)
            {
                Console.WriteLine("Bug no: {0}", dbi.BugNo);
                Console.WriteLine("Developer: {0}", dbi.Developer);
                Console.WriteLine("Last Reviewed: {0}",
                     dbi.LastReview);
                Console.WriteLine("Remarks: {0}", dbi.Message);
            }
        }

        //iterating through the method attribtues
        foreach (MethodInfo m in type.GetMethods())
        {
            foreach …
Run Code Online (Sandbox Code Playgroud)

c# casting runtime-error exception

0
推荐指数
1
解决办法
2161
查看次数

标签 统计

c# ×1

casting ×1

exception ×1

runtime-error ×1