【发布时间】:2013-09-20 20:47:46
【问题描述】:
上周我关闭了我正在工作的 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 没有给我更多的细节,烦人(我什至不知道它指的是哪个“路径”),但我可以添加更多信息:
在我的 Settings.settings 中有一个字符串
logFileDir指向一个日志文件目录。该路径当前有效,当我运行我的程序时,它会正确更新日志文件。-
表单加载方法很简单,如下:
if (Properties.Settings.Default.logFileDir != null) { _logFileDir = Properties.Settings.Default.logFileDir; PopulateLstDirectory(); } else { _logFileDir = null; } 当我运行代码时调用堆栈有时会增长,但新行似乎与我在上面粘贴的现有行重复。
- 我已尝试清理和重建我的解决方案和项目,以及多次重新启动 VS。
- 我在项目中没有任何第三方控件。
-
调用堆栈的第二高行说明了 Path.Combine - 我唯一一次调用该函数是在表单上某个按钮的 Click() 方法中:
string pathString = Path.Combine(_logFileDir, logFileName);
【问题讨论】:
-
这个问题只发生在这个表单或者你项目中的其他表单(如果有的话)?
-
@Steve 我暂时只有这个表格
-
通常当您在表单的构造函数中有一些无法在设计时执行的代码时发生,例如:文件访问和数据库访问。你那里有这样的代码吗?
-
@Steve 感谢您的建议!我将问题缩小到我创建的自定义排序字典类。它现在在一个单独的文件中,并显示了表单。尽管如此奇怪的行为。
-
@valsidalv 我知道这已经过时了,但是如果它再次发生,如果您打开一个新的 Visual Studio 实例并将其附加到调试器,您实际上可以调试 Windows 窗体设计器。见[这里](msdn.microsoft.com/en-us/library/ms996457.aspx)
标签: c# winforms visual-studio illegal-characters