【问题标题】:VS 2010 fails debugging: HttpException invalid file name for file monitoring in LoadControlVS 2010 调试失败:HttpException invalid file name for file monitoring in LoadControl
【发布时间】:2010-08-25 11:20:45
【问题描述】:

我真的在这件事上苦苦挣扎了好几天。

我已将 VS2010 中的 asp.net 3.5 项目迁移到 asp.net 4 项目。几周后一切正常。

不知何故,几天以来我收到了一个奇怪的错误。澄清这个项目的样子:

应用程序

这是一个基于 UserControl 的应用程序,应用程序区域由嵌套的 UserControl 层次结构组成,它们在 OnInit() 中加载其子控件,以使事件系统正常工作。

(注意:在 VS2008 和 .net 3.5 中一切正常!)

错误

现在,当我开始在 VS2010 中调试 Web 应用程序时,有时(!!!)会抛出 HttpException,并显示以下消息:

文件监控的文件名无效。

LoadControl()

大概 VS 使用这种方法在内部跟踪更改的文件以重新加载?

有人遇到过同样的问题吗?如果有,有什么解决办法吗?

编辑:部署 web 应用程序时,错误消失。它仅在调试时发生。我目前在 debug->exceptions 菜单中禁用了 HttpExceptions。但我也很高兴能再次抓住那些..

【问题讨论】:

  • 你解决过这个问题吗?我遇到了同样的事情。

标签: asp.net visual-studio-2010


【解决方案1】:

错误最终再次发生,但现在我发现您可以通过还原选项中的Enable Just My Code 选项来规避该问题:Tools->Options->Debugging->General,实际上它最初引入了损坏的调试行为。

必须设置选项Enable Just My Code

【讨论】:

  • 不是解决方案,它只是忽略了异常。
【解决方案2】:

我也遇到了这个问题,并且已经在 VS 中签入了 Enable Just My Code。但是,取消选中该选项,保存设置,然后重新检查后,问题就消失了。

【讨论】:

    【解决方案3】:

    这是一个需要使用反射的解决方案,这意味着网站应该在“完全信任”下运行

    using System;
    using System.Reflection;
    
    namespace Composite
    {
        internal static class BuildManagerHelper
        {
            /// <summary>
            /// Gets a user control. Prevents an exception that appears in Visual Studio while debugging
            /// </summary>
            /// <param name="virtualPath"></param>
            /// <returns></returns>
            public static Type GetCompiledType(string virtualPath)
            {
                try
                {
                    DisableUrlMetadataCaching(true);
    
                    return System.Web.Compilation.BuildManager.GetCompiledType(virtualPath);
                }
                finally
                {
                    DisableUrlMetadataCaching(false);
                }
            }
    
            /// <summary>
            /// Disabling the "url metadata caching" prevents <see cref="System.Web.HttpException" /> in debugger 
            /// </summary>
            /// <param name="disableCaching"></param>
            public static void DisableUrlMetadataCaching(bool disableCaching)
            {
                #if DEBUG
    
                var systemWeb = typeof (System.Web.TraceMode).Assembly;
                Type cachedPathData = systemWeb.GetType("System.Web.CachedPathData", false);
                if (cachedPathData == null) return;
    
                FieldInfo field = cachedPathData.GetField("s_doNotCacheUrlMetadata", BindingFlags.Static | BindingFlags.NonPublic);
                if (field == null) return;
    
                field.SetValue(null, disableCaching);
    
                #endif
            }
        }
    }
    

    附:这个问题困扰我好多年了

    【讨论】:

    • 如何将其集成到您的应用程序中?
    猜你喜欢
    • 2016-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2015-03-18
    • 2014-05-28
    • 1970-01-01
    相关资源
    最近更新 更多