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