【问题标题】:Root Element is Missing to web.configweb.config 中缺少根元素
【发布时间】:2014-08-17 06:39:02
【问题描述】:

这是我的问题:

配置错误

描述:处理此请求所需的配置文件时出错。请查看下面的具体错误详细信息并适当地修改您的配置文件。

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

来源错误:

[没有相关的源代码行]

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

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

【问题讨论】:

  • 报错说明很清楚。那么,您的实际问题是什么?为什么您不能根据该描述解决您的问题?如果我们应该提供帮助,请提供更多详细信息。例如,请提供配置文件(相关部分)。

标签: c# web-config


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    我在尝试运行使用 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 从另一台开发机器复制到我的机器上。

    【讨论】:

      猜你喜欢
      • 2012-04-24
      • 2016-05-10
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      相关资源
      最近更新 更多