2016-03-30 10 views
0

なぜType.GetTypeはnullを返し

Type.GetType("System.ComponentModel.DataAnnotations.KeyAttribute"); 

nullを返すのですか?

+4

'System.ComponentModel.DataAnnotations.dll'を参照していますか? – Sinatr

+2

http://stackoverflow.com/questions/1825147/type-gettypenamespace-a-b-classname-returns-nullの重複の可能性 –

答えて

1

あなたは修飾アセンブリ名を見つける方法

完全修飾アセンブリ名を使用し@Sinalrコメント

  • として参考System.ComponentModel.DataAnnonations.dll

    1. が必要になるでしょうか?

      Type.GetType("System.ComponentModel.DataAnnotations.KeyAttribute, System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); 
      

      はそれが役に立てば幸い:

      Console.WriteLine(typeof(System.ComponentModel.DataAnnotations.KeyAttribute).AssemblyQualifiedName.ToString()); 
      

      その後、アセンブリ名からタイプを取得することができます。

  • +0

    ありがとうございます –

    関連する問題