Today in the write reflection call failed, after debugging and analysis, the final solution, I will specify the following.
One, the phenomenon of error
Failed to load file or assembly "Dalsql" or one of its dependencies. The system could not find the specified file. Description: An unhandled exception occurred during the execution of the current WEB request. Check the stack trace for more information about the error and where the error occurred in the code. Exception Details: System.IO.FileNotFoundException: Failed to load file or assembly "Dalsql" or one of its dependencies. The system could not find the specified file. The error code is as follows:
<span style= "FONT-SIZE:14PX;" > ///<summary>
///Universal Object Reflection (including caching)
///</summary>
///<param name= "ClassName" > Class name to reflect </param>
///<returns></returns> public
static T CreateObject (String className)
{
var typeName = assemblystring + "." + ClassName;
Determine if the object is cached, read directly from the cache if it is already cached, or directly reflect and cache
var obj = (T) cachehelper.getcache (typeName);
if (obj = = null)
{
obj = (T) assembly.load (assemblystring). CreateInstance (TypeName, true);
Cachehelper.add (TypeName, obj, true);
}
return obj;
} </span>
Two, analyze the reasons and solve
is the path or name of the DLL wrong. After all, the reason is not deep enough to reflect the reflection of the call should be: Assembly.Load ("Assembly"). CreateInstance ("namespace. Class"), then let's check if our code is like this. This is the line (T) Assembly.Load (assemblystring). CreateInstance (TypeName, true); there are no mistakes. Finally found that the DLL was mistaken, "assembly" reads the corresponding DLL under the Web-tier Bin folder, that is, reflection-loaded assembly DLLs must be in the Web-layer Bin folder, otherwise there will be an error with the title. We can set the file name of the generated assembly by right-clicking the-> property on the class library item.
Third, configuration instructions
In the code we are accessing: private static readonly string assemblystring = configurationmanager.appsettings["DAL"]; The following settings should be set in the configuration file:
<appSettings>
<add key= "DAL" value= "Dalsql"/>
</appSettings>
OK, it's done, to strengthen the understanding of reflection.