【问题标题】:How to fix the "Could not find file 'C:\CoolApp.vshost.exe.config' exception?如何修复“找不到文件 'C:\CoolApp.vshost.exe.config' 异常?
【发布时间】:2011-02-06 06:14:05
【问题描述】:

我有一个程序使用浏览器 Winforms 控件导航到不同的网站,但在 5-10 秒后它会在 Visual Studio 中引发上述异常并突出显示这一行:

Application.Run (new MainForm ());

Program.cs.

我还可以看到异常位置,因为我打开了 CLR 异常选项。

但是为什么会这样。我没有对 vshost 做任何事情。我该如何解决这个问题?

编辑:调用堆栈:

    mscorlib.dll!System.IO.__Error.WinIOError(int errorCode, string maybeFullPath) + 0x4b7 bytes    
    mscorlib.dll!System.IO.FileStream.Init(string path, System.IO.FileMode mode, System.IO.FileAccess access = Read, int rights, bool useRights = false, System.IO.FileShare share, int bufferSize = 4096, System.IO.FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath = "CoolApp.vshost.exe.config", bool bFromProxy) + 0xa14 bytes    
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, string msgPath, bool bFromProxy) + 0x8a bytes 
    mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access) + 0x54 bytes    
    System.dll!System.Uri.ParseConfigFile(string file, out System.Uri.IdnScopeFromConfig idnStateConfig, out System.Uri.IriParsingFromConfig iriParsingConfig) Line 1106    C#
    System.dll!System.Uri.GetConfig(ref System.UriIdnScope idnScope = None, ref bool iriParsing = false) Line 1009  C#
    System.dll!System.Uri.InitializeUriConfig() Line 907 + 0x13 bytes   C#
    System.dll!System.Uri.InitializeUri(System.Uri.ParsingError err = None, System.UriKind uriKind, out System.UriFormatException e = null) Line 108 + 0x5 bytes    C#
    System.dll!System.Uri.CreateThis(string uri, bool dontEscape, System.UriKind uriKind) Line 50   C#
    System.Windows.Forms.dll!System.Windows.Forms.WebBrowser.WebBrowserEvent.BeforeNavigate2(object pDisp, ref object urlObject, ref object flags, ref object targetFrameName, ref object postData, ref object headers, ref bool cancel = false) Line 1934 + 0x1a bytes C#
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason, int pvLoopData) Line 2106 + 0xc bytes  C#
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) Line 3377 + 0x35 bytes    C#
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3261 + 0xd bytes   C#
>   CoolApp.exe!CoolApp.Program.Main() Line 18 + 0x28 bytes C#
    [Native to Managed Transition]  
    [Managed to Native Transition]  
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x47 bytes  
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x9b bytes    
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x4d bytes   

【问题讨论】:

  • @Hans:我添加了调用堆栈,这是你想要的吗?
  • C:\CoolApp 是您的 exe 文件夹吗?那里有 *.config 文件吗?您是在复制/移动 .EXE 还是更改当前文件夹?
  • @Hans:谢谢,我缩短了路径,但它在我的原始项目 bin/debug 或发布文件夹中。我在那里看不到配置文件,只有 exe、dll、pdb、vshost.exe 和 vshost.exe.manifest 文件。

标签: c# .net winforms exception


【解决方案1】:

您可以从这里找到有关 VSHost 的详细信息:http://blogs.msdn.com/b/dtemp/archive/2004/08/17/215764.aspx

我也在 SO 中发现了一个类似的问题:mysterious exception "Could not find file 'D:\xxxx\bin\Debug\xxx.vshost.exe.config'."

【讨论】:

    【解决方案2】:

    在我看来,您试图在没有安装调试器的机器上运行以调试模式编译的程序。

    【讨论】:

    • 谢谢,但我正在编译发布版本。调试器已安装。
    【解决方案3】:

    为了解决此问题,请尝试选中工具/选项/调试/常规中的“仅启用我的代码(仅限托管)”框

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 2019-09-19
      相关资源
      最近更新 更多