I found this error during packaging because I moved the position of my project (from drive C to drive D) and checked the error code:
Dim strdb as string = system. configuration. configurationsettings. etettings ("dbuser") 'modify the configuration file to check the table. '// <Summary>' // depiction: <instantiate the class of the User table in a dal> '// </Summary>' // <Param name = "<Parameter Name>"> <parameter description> </Param> '// <returns>' // <return value is a Boolean value> '// </returns> Public Function createuserinfo () as idal. iuser return ctype (assembly. load ("Dal "). createinstance ("Dal "&". "& strdb), iuser) end Function
The strdb value above is obtained from the configuration file. I personally think that the configuration file is a variable library, instead of writing this variable in the Code, the configuration file loads the value when the system is running.
Taking advantage of this opportunity, I want to explain my understanding of reflection:
When using reflection, we must first understand the relationships between several classes in the namespace:
System. Reflection namespace
(1) appdomain: application domain, which can be understood as a logical container of a group of assemblies
(2) Assembly: Assembly class
(3) module: module class
(4) type: Use reflection to obtain the core class of the type information.
Appdomain can contain multiple assemblies, one assembly can contain multiple modules, and one module can contain multiple types.
In the data room charging system we designed, the above Code is that we dynamically load an assembly. Three methods can be used to dynamically load the Assembly: load, static Methods of the three assembly: loadfrom and loadwithpartialname.
Obviously, we use the first one. Assembly. load (), the order in which the Assembly is loaded is: first it goes back to the Global Assembly Cache for search, then to the root directory of the application, and finally to the private path of the application.
the usage of Assembly. Load ("") is described as follows.
it is not a namespace. Commonly used is the Assembly name, that is, the DLL name
reload list
Name Description
assembly. load (assemblyname) loads an Assembly Based on the assemblyname of the given assembly.
about reflection assembly. load ("assembly "). createinstance ("namespace. class ")
no matter at which layer the (" assembly ") in this Code reads the DLL in the bin folder of the web layer, that is to say, the Assembly DLL of the class you reflected must exist under the bin of the web layer.
assembly. Load ("assembly name")
After reading our code: the Assembly name is "Dal" (DAL is my d-layer package), you can see it more clearly:
We can see that there is no Dal in my UI Layer (web layer. DLL file, if any, should be in the red line by letter, so we will go to the Dal layer (DAL \ bin \ release) to Dal. copy DLL-related files to the web layer. Result:
Okay. Just run it.