Home > Net >  The Assembly. The problem of CreateInstance great spirit
The Assembly. The problem of CreateInstance great spirit

Time:09-30

I have 2 classes under a set of procedures, can use reflection to create a class instance, what is a class is empty
The Assembly Assembly=Assembly. The Load (" Cjf. Dal ");
Object obj1=assembly. CreateInstance (" Cjf. Dal. BookInfoDal ");
Object obj2=assembly. CreateInstance (" Cjf. Dal. BookTypeDal ");
An assembly that is not empty, obj1 can create instances, but obj2 returns null is something wrong

CodePudding user response:

The source code. You can open the Assembly CreateIntance see bai, a total of only three or four lines of code,

Whenever possible, should be combined with the.net framework source code to learn. The net, this is a must skill,

Or what is called studied the.net? Read the source code can distinguish between a programmer did beneath the surface potential,

CodePudding user response:

You can think of there are so few things
1, there is no Cjf. Dal. BookTypeDal this class, spelt wrong
2, Cjf. Dal. BookTypeDal not public
3, Cjf. Dal. BookTypeDal no default constructor
4, Cjf. Dal. BookTypeDal is abstract, not structure

CodePudding user response:

refer to the second floor shingoscar response:
can think of there are so few things
1, there is no Cjf. Dal. BookTypeDal this class, spelt wrong
2, Cjf. Dal. BookTypeDal not public
3, Cjf. Dal. BookTypeDal no default constructor
4, Cjf. Dal. BookTypeDal is abstract, cannot construct



This is two classes, inherit more implement interfaces are the same, the name of the class I was copied

CodePudding user response:

C # reflection

CodePudding user response:

Use first MethodInfo [] Minfo=typeof (Cjf. Dal. BookTypeDal). GetMethods (BindingFlags. Instance | BindingFlags. Public); Detection under the class has several constructors, what type,
Methods CreateInstance (types, the constructor argument string []), would transmit the parameters in
You can also use the Activator. The CreateInstance () implementation

CodePudding user response:

Returns null should be able to capture the error? Take a look at the error message

CodePudding user response:

reference 1st floor interacting in a professional developer response:
. You can open the Assembly CreateIntance source code to see bai, a total of only three or four lines of code,

Whenever possible, should be combined with the.net framework source code to learn. The net, this is a must skill,

Or what is called studied the.net? Read the source code can distinguish between a programmer did beneath the surface potential,

Are you what all can't, haven't seen you positive solve the problem, also abandon the abandon of the everyday, so much why don't you go to develop an operating system?

CodePudding user response:

refer to 7th floor qq_36866347 response:
Quote: refer to 1st floor interacting in a professional developer response:

The source code. You can open the Assembly CreateIntance see bai, a total of only three or four lines of code,

Whenever possible, should be combined with the.net framework source code to learn. The net, this is a must skill,

Or what is called studied the.net? Read the source code can distinguish between a programmer did beneath the surface potential,

Are you what all can't, haven't seen you positive solve the problem, also abandon the abandon of the everyday, so much why don't you go to develop an operating system?

Online search to the problem is to solve the problem, not to see what the problem is not solved, also where where B B.
  •  Tags:  
  • C #
  • Related