在没有输入方法的情况下,在方法调用时抛出FileNotFoundException

时间:2014-06-04 17:50:57

标签: c# asp.net .net

所以我遇到了一个真正令人困惑的FileNotFoundException,我不确定如何排除故障。

我有一个.cs文件,作为网页方法的基本模板。在其中,我有以下私有方法:

private void Initialize(object sender, EventArgs e)
    {
        // Some initialize functions and...

        AddWebAnalyticsScript();
    }

AddWebAnalyticsScript()是同一个类中的私有函数。它处理一些Google Web Analytics代码的加载。通过这个类进行调试,我看到AddWebAnalyticsScript()为依赖程序集抛出了FileNotFoundException。

我尝试在函数定义中放置断点,因为我假设其中有一些逻辑引用了缺少的程序集。但是当我在函数定义中放置断点时,我发现在函数中执行任何代码之前抛出此异常;它会在通话时立即发生。我以前从未见过这种情况,但我无法找到有关类似问题的任何文档。从概念上讲,我不明白为什么在同一个类中定义的函数的CALL会查找程序集,直到实际执行包含的代码为止。

此外,该程序集似乎完全出现在References下面。

所以我很神秘。除了在函数定义中放置断点之外,我还无法考虑如何进行故障排除。使用调试器'步入'对AddWebAnalyticsScript()的操作;导致异常被立即抛出。

错误文字;

{"Could not load file or assembly 'myApplication.Frameworks.WebAnalyticsInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0113ab8eb0779932' or one of its dependencies. The system cannot find the file specified.":"myApplication.Frameworks.WebAnalyticsInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0113ab8eb0779932"}

堆栈追踪:

at MyApplication.PageTemplate.AddWebAnalyticsScript()
at MyApplication.PageTemplate.Initialize(Object sender, EventArgs e) in D:\\{filepath}:line 246
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnInit(EventArgs e)
at System.Web.UI.UserControl.OnInit(EventArgs e)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

来自融合日志:

LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\MyApp\Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: MyApp.Frameworks.WebAnalyticsInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0113ab8eb0779932
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

正如您所说,在方法内部执行代码之前,您定义的方法无法调用外部程序集。

您还提到了实际引用的违规程序集。这并不一定意味着可以定位到该组件的所有相关组件。

要解决dll加载问题,请始终使用Fusion Logging。我引用的文章包含有关如何打开并使用它的信息。这很简单。

可能有很多原因导致无法加载程序集,包括错误图像格式(x64 vs x86)的异常,错误的搜索路径等。这些都可以通过Fusion Log区分,因为它记录了所有的尝试不同的路径,并详细说明了某个装配失败的原因。