Run Time error in System.ComponentModel

Earth_2 1 Reputation point
2022-12-01T07:27:39.627+00:00

Hi Team,

I see below exception in System.ComponentModel... Would you please help me to understand more on this

265999-image.png

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,980 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,108 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,178 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 68,236 Reputation points
    2022-12-01T22:01:28.973+00:00

    a type can have multiple attributes of many types. you are try to cast an arbitrary attributes to one specific one (System.ComponentModel.TypeDescriptionProviderAttribute). in your case none of the attributes are this type. you need to test the attribute type before casting or use the handy as type (which return null if not a match).

    0 comments No comments

  2. QiYou-MSFT 4,326 Reputation points Microsoft Vendor
    2022-12-02T07:46:22.71+00:00

    Hi @Earth_2
    Based on the error message you gave, this is a type conversion issue.
    The first thing you can use is to check if the object is compatible with a given type, and if it is compatible, it returns true, otherwise it returns false and no exception is thrown. Before type conversion, you can use is to determine whether the object is compatible with a given type, and if so, then convert. For example:

    string str="test";  
    object obj=str;  
    if(obj is string){string str2=(string)obj};  
    

    Secondly, we can use as: for conversion between reference types, direct conversion, if the conversion is successful, it will return the converted object, if the conversion fails, return null, and do not throw an exception. For example:

    string str="test";  
    object obj=str;  
    string str2=obj as string;  
    if(str2!=null){return "success"}  
    

    If you can share a little bit of the other code, I think I can pinpoint the problem more precisely.

    Best Regards
    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.