Lessons from using. net reflection

Source: Internet
Author: User

 

A small test project was created based on the PetShop architecture. reflection was used in the factory class. After the project was successfully generated, the website was run. when the project was run to the factory class, the system always throws "type Initial Value Setting item raises an exception" and adds breakpoint debugging, but it still cannot be found. google queries found that there was a problem with the namespace and Assembly naming. I found some problems with the help of my colleague circlelee, And I have summarized them here to share them with my friends who have the same problems;

 

1. The introduction of namespaces is essential, that is, in addition to referencing in the class library, you also need to add references to the Assembly to be loaded through reflection under the binfile in the web layer;

 

2. The Assembly path configured through webconfig must be consistent with the Assembly name on the "properties" page of the class library;

 

If the above two points are ensured, "exceptions caused by type initial values" should not occur ".

 

Author Hong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.