title: dotnet restore: An error occurred while retrieving package... metadata Root element is missing
body: <p>I have a nuget/docker build issue that I’ve spent a couple of days debugging and am running out of ideas: Do you know why I am getting the below error?</p>
  
  <p>The issue is with one asp.net core solution (others that are very similar are unaffected): Although I can build the affected solution in visual studio 2019 using the docker compose file, it will not work using the dockerfile and so the docker build command can’t be run.</p>
  
  <p>If I run the dockerfile by doing a build as below in command prompt:</p>
  
  <pre><code>docker build -f MStoreBosGateway/MStoreBosGatewayApi/Dockerfile --pull --no-cache -t mstorebosgateway:0.041 .
  </code></pre>
  
  <p>then I get the following error:</p>
  
  <pre><code>Step 11/26 : RUN dotnet restore "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj"
  &gt;  ---&gt; Running in 30819cb5db4f
  &gt; /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error
  &gt; occurred while retrieving package metadata for
  &gt; 'System.Text.Encodings.Web.4.5.0' from source
  &gt; '/usr/share/dotnet/sdk/NuGetFallbackFolder'.
  &gt; [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
  &gt; /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root
  &gt; element is missing.
  &gt; [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
  &gt; The command '/bin/sh -c dotnet restore
  &gt; "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj"'
  &gt; returned a non-zero code: 1
  </code></pre>
  
  <p>I’ve put RUN echo commands after each line in the dockerfile so it looks like it is the dotnet restore that is causing this issue. If I run the dotnet restore command by itself it runs ok.</p>
  
  <p>To try to resolve this I’ve done quite a few things e.g.</p>
  
  <ul>
  <li>-Deleted the obj and bin folders from this solution and projects,</li>
  <li>-Uninstalled and reinstalled nuget,</li>
  <li>-Deleted the nuget caches to force the packages to be redownloaded,</li>
  <li>-uninstalled and reinstalled the dotnet core sdks,</li>
  <li>-Removed the package mentioned in the error message ('System.Text.Encodings.Web.4.5.0) from the project file (this did
  not cause any errors so must have been redundant anyway). That did
  not affect this error and it restores this package so there must be
  something else saying to use this package or possibly system packages
  are all included by default anyway.</li>
  </ul>
  
  <p>My colleague can build this project and has sent me a copy of it that he can build; I get the same issue building his copy so assume it’s something external to the project.</p>
  
  <p>I have added below the output if I add ‘ –verbosity detailed’ to the dotnet restore command in the docker file.</p>
  
  <pre><code>           GET https://api.nuget.org/v3-flatcontainer/microsoft.extensions.dependencyinjection.abstractions/index.json
             OK https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/index.json 342ms
             GET https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg
             OK https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg 52ms
             GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.authentication/index.json
             GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
       1&gt;/usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
  /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root element is missing. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
             OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/index.json 156ms
             GET https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg
             OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/index.json 160ms
             GET https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg
             OK https://api.nuget.org/v3-flatcontainer/automapper/index.json 155ms
             GET https://api.nuget.org/v3-flatcontainer/automapper/8.0.0/automapper.8.0.0.nupkg
             OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg 44ms
             OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg 49ms
             GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.apiexplorer/index.json
             GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.core/index.json
             GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.dataannotations/index.json
           NuGet.Protocol.Core.Types.FatalProtocolException: An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. ---&gt; NuGet.Packaging.Core.PackagingException: An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. ---&gt; System.Xml.XmlException: Root element is missing.
              at System.Xml.XmlTextReaderImpl.Throw(Exception e)
              at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
              at System.Xml.XmlTextReaderImpl.Read()
              at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
              at NuGet.Packaging.Core.NuspecCoreReaderBase.LoadXml(Stream stream, Boolean leaveStreamOpen)
              at NuGet.Packaging.Core.NuspecCoreReaderBase..ctor(Stream stream, Boolean leaveStreamOpen)
              at NuGet.Packaging.NuspecReader..ctor(Stream stream)
              at NuGet.Protocol.LocalPackageFileCache.GetNuspec(String manifestPath, String expandedPath)
              at NuGet.Protocol.LocalPackageFileCache.&lt;&gt;c__DisplayClass6_1.&lt;GetOrAddNuspec&gt;b__1()
              at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
              at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
              at System.Lazy`1.CreateValue()
              at NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](String id, NuGetVersion version, Func`2 process)
              --- End of inner exception stack trace ---
              --- End of inner exception stack trace ---
              at NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](String id, NuGetVersion version, Func`2 process)
              at NuGet.Protocol.LocalV3FindPackageByIdResource.GetDependencyInfoAsync(String id, NuGetVersion version, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
              at NuGet.Commands.SourceRepositoryDependencyProvider.GetDependenciesCoreAsync(LibraryIdentity match, NuGetFramework targetFramework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
              at NuGet.Commands.SourceRepositoryDependencyProvider.&lt;&gt;c__DisplayClass21_0.&lt;&lt;GetDependenciesAsync&gt;b__0&gt;d.MoveNext()
           --- End of stack trace from previous location where exception was thrown ---
              at NuGet.Commands.SourceRepositoryDependencyProvider.GetDependenciesAsync(LibraryIdentity libraryIdentity, NuGetFramework targetFramework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
              at NuGet.DependencyResolver.ResolverUtility.CreateGraphItemAsync(RemoteMatch match, NuGetFramework framework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
              at NuGet.DependencyResolver.ResolverUtility.FindLibraryEntryAsync(LibraryRange libraryRange, NuGetFramework framework, String runtimeIdentifier, RemoteWalkContext context, CancellationToken cancellationToken)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
              at NuGet.Commands.ProjectRestoreCommand.WalkDependenciesAsync(LibraryRange projectRange, NuGetFramework framework, String runtimeIdentifier, RuntimeGraph runtimeGraph, RemoteDependencyWalker walker, RemoteWalkContext context, CancellationToken token)
              at NuGet.Commands.ProjectRestoreCommand.TryRestoreAsync(LibraryRange projectRange, IEnumerable`1 frameworkRuntimePairs, NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteDependencyWalker remoteWalker, RemoteWalkContext context, Boolean forceRuntimeGraphCreation, CancellationToken token, TelemetryActivity telemetryActivity)
              at NuGet.Commands.RestoreCommand.ExecuteRestoreAsync(NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteWalkContext context, CancellationToken token, TelemetryActivity telemetryActivity)
              at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token)
              at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
              at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
              at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List`1 restoreTasks)
              at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable`1 restoreRequests, RestoreArgs restoreContext, CancellationToken token)
              at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token)
              at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
         Done executing task "RestoreTask" -- FAILED.
       1&gt;Done building target "Restore" in project "MStoreBOSGatewayApi.csproj" -- FAILED.
       1&gt;Done Building Project "/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" (Restore target(s)) -- FAILED.
  
  Build FAILED.
  
         "/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" (Restore target) (1) -&gt;
         (Restore target) -&gt;
           /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
         /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root element is missing. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
  
      0 Warning(s)
      1 Error(s)
  
  Time Elapsed 00:00:04.70
  The command '/bin/sh -c dotnet restore "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" --verbosity detailed' returned a non-zero code: 1
  
  C:\Applications\VB2017Apps\MStoreBOSGateway&gt;
  </code></pre>