错误显示如下:System.IO.FileNotFoundException: Could not load file or assembly 'FlyingCanada1.SQLServerDAL' or one of its dependencies. The system cannot find the file specified代码如下,我自己测试classname的值是对的,大虾们给看看那里可能有问题,谢谢。namespace FlyingCanada1.DALFactory { public sealed class DataAccess { private static readonly string path = ConfigurationManager.AppSettings["WebDAL"];
private DataAccess() { }
public static FlyingCanada1.IDAL.IAirport CreateAirport() {
string className = path + ".Airport";
return (FlyingCanada1.IDAL.IAirport)Assembly.Load(path).CreateInstance(className);
}
}
}namespace FlyingCanada1.IDAL
{
public interface IAirport
{
IList<AirportInfo> GetAirports(); AirportInfo GetAirport(string designator);
}
}
Web.config
<appSettings> <add key="WebDAL" value="FlyingCanada1.SQLServerDAL"/> </appSettings>namespace FlyingCanada1.SQLServerDAL
{
public class Airport: IAirport
{
private const string SQL_SELECT_AIRPORTS = "SELECT designator, latitude, longitude FROM airportData";
private const string SQL_SELECT_AIRPORT = "SELECT designator, latitude, longitude FROM [airportData] WHERE designator = @designator";
private const string PARM_AIRPORT_DESIGNATOR = "@designator";
public IList<AirportInfo> GetAirports() { IList<AirportInfo> airports = new List<AirportInfo>(); using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT_AIRPORTS, null))
{
while (rdr.Read()) {
AirportInfo airport = new AirportInfo(rdr.GetString(0), rdr.GetDouble(1), rdr.GetDouble(2));
airports.Add(airport);
}
}
return airports;
}
public AirportInfo GetAirport(string designator) {
AirportInfo airport = null; SqlParameter parm = new SqlParameter(PARM_AIRPORT_DESIGNATOR, SqlDbType.VarChar, 5);
parm.Value = designator; using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT_AIRPORT, parm)) {
if (rdr.Read())
airport = new AirportInfo(rdr.GetString(0), rdr.GetDouble(1), rdr.GetDouble(2));
else
airport = new AirportInfo();
}
return airport;
}
}
}
private DataAccess() { }
public static FlyingCanada1.IDAL.IAirport CreateAirport() {
string className = path + ".Airport";
return (FlyingCanada1.IDAL.IAirport)Assembly.Load(path).CreateInstance(className);
}
}
}namespace FlyingCanada1.IDAL
{
public interface IAirport
{
IList<AirportInfo> GetAirports(); AirportInfo GetAirport(string designator);
}
}
Web.config
<appSettings> <add key="WebDAL" value="FlyingCanada1.SQLServerDAL"/> </appSettings>namespace FlyingCanada1.SQLServerDAL
{
public class Airport: IAirport
{
private const string SQL_SELECT_AIRPORTS = "SELECT designator, latitude, longitude FROM airportData";
private const string SQL_SELECT_AIRPORT = "SELECT designator, latitude, longitude FROM [airportData] WHERE designator = @designator";
private const string PARM_AIRPORT_DESIGNATOR = "@designator";
public IList<AirportInfo> GetAirports() { IList<AirportInfo> airports = new List<AirportInfo>(); using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT_AIRPORTS, null))
{
while (rdr.Read()) {
AirportInfo airport = new AirportInfo(rdr.GetString(0), rdr.GetDouble(1), rdr.GetDouble(2));
airports.Add(airport);
}
}
return airports;
}
public AirportInfo GetAirport(string designator) {
AirportInfo airport = null; SqlParameter parm = new SqlParameter(PARM_AIRPORT_DESIGNATOR, SqlDbType.VarChar, 5);
parm.Value = designator; using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, SQL_SELECT_AIRPORT, parm)) {
if (rdr.Read())
airport = new AirportInfo(rdr.GetString(0), rdr.GetDouble(1), rdr.GetDouble(2));
else
airport = new AirportInfo();
}
return airport;
}
}
}
解决方案 »
- VS2012总安装失败
- 关于Cookie!求解决,在线等!
- 网页提交时提示说无法验证数据,怎么回事?
- ADO.NET操作ACCESS的问题!
- jQuery 长度设置
- 判断一个从webservice获取的DataSet对象的第一列是否包含在另一个DataSet对象里面?
- 帮我看看这个怎么做好
- 有代码,提示COM工厂未注册,如何解决?
- 请教关于dundas chart问题,怎么控制X轴显示,如显示一天中24小时,1,2,...24?
- 简单的饭店项目(菜鸟征集想法,有满意的方案,马上给分^_^)
- NullReferenceException: 未将对象引用设置到对象的实例 求助,在线等
- c#线程问题
FlyingCanada1.SQLServerDAL
无法装载文件或程序就是没找到dll“FlyingCanada1.SQLServerDAL”么
ConfigurationManager.AppSettings["WebDAL"];
<appSettings> <add key="WebDAL" value="路径+FlyingCanada1.SQLServerDAL"/> </appSettings>
估计你的程序集名字是SQLServerDAL。把它改成FlyingCanada1.SQLServerDAL试试。