GetType on a class in a referenced assembly fails

后端 未结 2 546
天涯浪人
天涯浪人 2021-01-14 13:33

I have an asp.net web project that references a domain project.

From within the web project, I want to create an instance of a class from the domain project using re

相关标签:
2条回答
  • 2021-01-14 14:15

    You can get a type by name alone if you have the Assembly it's in. Would that work for you?

    That way you could specify the assembly name in a separate location from the types you're trying to access.

    Assembly assembly = typeof(System.Linq.Enumerable).Assembly;
    Type type = assembly.GetType("System.Linq.Enumerable");
    
    0 讨论(0)
  • 2021-01-14 14:22

    You can do something like this, ignoring those attributes:

    Dim myType as Type = Type.GetType("System.Linq.Enumerable")); 
    

    or:

    Dim myType as Type = Type.GetType("System.Linq.Enumerable, System.Core")); 
    
    0 讨论(0)
提交回复
热议问题