根元素缺少web.config

时间:2014-08-17 06:39:03

标签: c# web-config

这是我的问题:

  

配置错误

     

描述:处理为此请求提供服务所需的配置文件时发生错误。请查看下面的具体错误详细信息并相应地修改配置文件。

     

分析器错误消息:缺少根元素。

     

来源错误:

     

[没有相关的源代码行]

     

源文件:C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Config \ web.config行:0

     

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18408

2 个答案:

答案 0 :(得分:1)

在Web.Config的开头,可能存在无效字符。你应该看到:

<?xml version="1.0" encoding="utf-8"?> <configuration>

那你到底有什么?如果您想要更具体的答案,请从最顶层发布前几行。

答案 1 :(得分:0)

我在尝试运行使用Visual Studio 2017构建的.Net应用程序时收到的实际错误消息是:

System.Configuration.ConfigurationErrorsException: Root element is missing. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config) ---> System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Configuration.XmlUtil..ctor(Stream stream, String name, Boolean readToFirstElement, ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
   --- End of inner exception stack trace ---
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
   at System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(Type typeConfigHost, Object[] hostInitConfigurationParams)
   at System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, String site, String locationSubPath, String server, String userName, String password, IntPtr tokenHandle)
   at System.Web.Hosting.HostingEnvironment.get_CacheStoreProviderSettings()
   at System.Web.Caching.Cache.GetObjectCache(Boolean createIfDoesNotExist)
   at System.Web.Caching.Cache.get_Item(String key)

事实证明,路径中列出的web.config已损坏,并且是记事本中显示为空格的43K。解决方案是将未损坏的web.config从另一台开发机器复制到我的。