【发布时间】:2011-01-18 22:00:15
【问题描述】:
Assembly assembly = Assembly.LoadFrom("Logic\\bin\\Debug\\Logic.dll");
Type queryManagerType = assembly.GetType("Logic." + HttpContext.Current.Session["lang_name"] + "SearchQueryManager");
var queryManager = (ISearchQueryManager)Activator.CreateInstance(queryManagerType);
public interface ISearchQueryManager
{
IList<Advertisements> ApplyQueries(string searchQuery, int page, int pageSize, string orderBy, out int count);
}
public class SlovenianSearchQueryManager : ISearchQueryManager
{
...
}
但我明白了
无法将“Logic.SlovenianSearchQueryManager”类型的对象转换为“Logic.ISearchQueryManager”类型。
编辑:整个堆栈跟踪
System.InvalidCastException 是 用户代码未处理
Message="无法转换类型的对象 'Logic.SlovenianSearchQueryManager' 到 输入“Logic.ISearchQueryManager”。”
Source="ViaMura.Web.Module"
堆栈跟踪: 在 ViaMura.Web.Module.WebController.GetAdvertismentsByRawQuery(字符串 rawQuery, Int32 page, Int32 pageSize, 字符串 orderBy, Int32& count) in D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web.Module\WebController.cs:line 32 在 ViaMura.Web.Module.Views.SearchResultsPresenter.OnResultsLoad(Int32 page, Int32 pageSize, String orderBy) 在 D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web.Module\Views\SearchResultsPresenter.cs:line 43 在 ViaMura.Web.SearchResults.SearchAdvertisments() 在 D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\SearchResults.aspx.cs:line 155 在 ViaMura.Web.SearchResults.Page_Load(对象 发件人,EventArgs e) 在 D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\SearchResults.aspx.cs:line 149 在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, 对象 o, 对象 t, EventArgs e) 在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象 发件人,EventArgs e) 在 System.Web.UI.Control.OnLoad(EventArgs e) 在 ViaMura.Web.App_Code.PageControllers.BasePage.OnLoad(EventArgs e) 在 D:\PROJEKTI\crawler\WebCrawlerSuite\ViaMura.Web\App_Code\PageControllers\BasePage.cs:89 行 在 System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔值 includeStagesAfterAsyncPoint)
内部异常:
编辑2:
string a1 = typeof (ISearchQueryManager).Assembly.Location;
string a2 = typeof(SlovenianSearchQueryManager).Assembly.Location
给我同样的结果:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET 文件\root\5438a399\53975f83\assembly\dl3\0f9540b5\15407fe2_5db7cb01\Logic.DLL
但是
string a3 = queryManagerType.Assembly.Location;
给了我不同的路径:
D:\PROJEKTI\crawler\WebCrawlerSuite\WebCrawler.Logic\bin\Debug\WebCrawler.Logic.dll
【问题讨论】:
-
请发布完整的异常堆栈跟踪。我怀疑你在两个不同的程序集中定义了这个
ISearchQueryManager接口。 -
@Darin 或两个命名空间
标签: c#