Windows窗体设计器错误"路径中包含非法字符"。

5

上周我关闭了正在使用的VS 2012(11.0)项目,今天我无法加载Windows表单设计器。相反,我收到以下消息:“在加载设计师之前防止可能的数据丢失,必须解决以下错误:路径中有非法字符。”没有忽略该消息的选项。我仍然可以运行我的代码,它也能正常工作。请准备好一个冗长的调用堆栈:

at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.VisualStudio.Platform.VsAppDomainManager.d__1.MoveNext()
at Microsoft.VisualStudio.Platform.VsAppDomainManager.InnerResolveHandler(String name)
at Microsoft.VisualStudio.Platform.VsAppDomainManager.ResolveHandler(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, ReferenceType refType)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.AggregateTypeResolutionService.GetType(String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.GetType(String typeName)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host) )

很遗憾,Visual Studio没有给我更多的细节(我甚至不知道它指的是哪个“路径”),但我可以补充一些信息:

  • In my Settings.settings I have a string logFileDir that points to a log file directory. The path is currently valid and when I run my program it correctly updates the log file.

  • The form load method is simple and as follows:

    if (Properties.Settings.Default.logFileDir != null)
    {
        _logFileDir = Properties.Settings.Default.logFileDir;
        PopulateLstDirectory();
    }
    else
    {
        _logFileDir = null;
    }
    
  • The call stack grows sometimes when I run the code but the new lines appear to be duplicates of existing ones that I pasted above.

  • I have tried cleaning & rebuilding my solution and project, as well as restarting VS multiple times.
  • I don't have any 3rd party controls in the project.
  • The 2nd highest line of the call stack says something about Path.Combine - the only time I call that function is in the Click() method of some button on my form:

    string pathString = Path.Combine(_logFileDir, logFileName);
    

这个问题只发生在这个表单上,还是在您的项目中的其他表单(如果有)也会出现? - Steve
@Steve 目前我只有这一个表单。 - valsidalv
5
通常发生在表单构造函数中存在某些无法在设计时执行的代码,例如:文件访问和数据库访问。你的构造函数中有这样的代码吗? - VahidNaderi
为了排除设计师的问题,请尝试添加一个虚拟表单,并在其中使用第一个表单中使用的一些控件。 - Steve
1
@Steve 感谢您的建议!我将问题缩小到了我创建的自定义排序字典类上。现在它已经在一个单独的文件中,表格也显示出来了。尽管如此,这种行为还是有些奇怪。 - valsidalv
1
@valsidalv 我知道这是一种旧的方法,但如果再次发生这种情况,您实际上可以通过打开一个新的 Visual Studio 实例并将其连接到调试器来调试 Windows Forms 设计器。详见 此处 - Jcl
1个回答

0
啊,当这种情况发生时真是令人烦恼。 您需要查看form.designer文件以了解问题所在。 在代码视图中编译程序并查看错误,它会告诉您问题出在哪里。只需进入.designer文件并纠正错误即可。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接