Failed to load file or assembly "Sqlserverdal" or one of its dependencies. The system cannot find the file specified.

Source: Internet
Author: User

Today, I encountered a very strange problem, after using the Factory mode, went out to find the assembly problem:
Failed to load file or assembly "Tianyige.sqlserverdal" or one of its dependencies. The system cannot find the file specified.

Solution Ideas:
The problem with this kind of problem is that the assembly and namespace names are confused, such as namespaces called Sqlserverdal, and assemblies may be called "tianyige.sqlserverdal", or "Sqlserverdal", An error occurred that could not be found for the object. The workaround is to correspond to a good assembly name:
Assembly.Load ("Tianyige.sqlserverdal"). CreateInstance ("Tianyige.SqlServerDAL.Category"); Locate the appropriate DLL under the Bin folder to determine its name.
And this time the name corresponds well, see my eyes are spent, a little wrong, or there is a problem. Finally, the DLL file [Tianyige.sqlserverdal] of the file in the error message is copied to the bin directory under the website app, and the problem is resolved.

Imitation pet shop4 Do a simple example of a factory model, a preliminary understanding of the process, to do a summary.
First, create the project Idal, including several interfaces, such as Iorder, is the database operation interface about order.
Second, create the project Sqlserverdal, which contains an order class, inherits the Iorder interface, specifically implements several functions declared in the interface.
Third, create the project Dalfactory, is a database interface factory, responsible for the selected database type (in Web. config, get such as <add key= "Webdal" value= "Sqlserverdal"/>) To create an instance of the corresponding database operation interface. such as the following code:
public static Iorder Createorder ()
{
String path = "Sqlserverdal";
String className = Path + ". Index ";
Return (Iorder) assembly.load (path). CreateInstance (ClassName);
}
Iv. Create the Project BLL, responsible for business logic implementation. Where the database operation function needs to be called when declaring
private static Iorder Iorder = Dataaccess.createorder ();
Then call the function declared in Iorder (defined in the Sqlserverdal.order Class).
The above is a basic process, which requires a few points to note:
1, Data Interface Factory dalfactory in the Createorder function is declared static, and other relevant places to use static, because here is the use of reflection dynamic loading of the assembly, so load once is enough, the Internet accidentally read the data, It is said that even multiple execution of the LOAD statement is only loaded once.
2, the "Failed to load file or assembly" Sqlserverdal "or one of its dependencies appears. The system could not find the specified file "case. In fact, the thief is simple, is unable to find the assembly, mainly does not understand the mechanism of its operation, in fact, if
Assembly.Load (Path). CreateInstance (ClassName);
Written
Assembly.Load ("SQLServerDAL.dll"). CreateInstance (ClassName);
It is clear that this is not looking for a namespace, but a DLL file in the bin. The name of the DLL file generated by the project Sqlserverdal default is SQLServerDAL.dll, and the above error will occur. Then just change the assembly name to "Sqlserverdal" in the Project property.
Programming road too long, a lot of foundation to play, too much technology to learn, quickly lost confidence!

Failed to load file or assembly "Sqlserverdal" or one of its dependencies. The system cannot find the file specified.

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.