简体   繁体   中英

Root Element is Missing to web.config

This is my problem:

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Root element is missing.

Source Error:

[No relevant source lines]

Source File: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Config\\web.config Line: 0

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

Chances are there's an invalid character at the start of your Web.Config. You should see:

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

So what do you actually have? Post the first few lines from the very top if you want more specific answers.

The actual error message I received on this while trying to run a .Net Application built with Visual Studio 2017 was:

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)

And it turned out, the web.config listed in the path had become corrupted and was 43K of what appeared as blank spaces in notepad. The solution was to copy an uncorrupted web.config from another development machine to mine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM