Skip to content

Microsoft.Web.LibraryManager.Build.RestoreTask exception #514

Closed

Description

@ImGonaRot

Microsoft.Web.LibraryManager.Build 2.0.76
VS 2017 15.9.11
ASP.NET Web Form project using 4.6.1

On some machine in our office using VS 2017, we can't build our ASP.NET project that has the "auto restore" enabled for LibMan.
Some machines with VS 2017 using the same project build fine.

What seems to be odd is that our ASP.NET project references "System.Net.Http Version 4.0.0.0" yet the LibraryManager is referencing "System.Net.Http Version 4.2.0.0".
I think this is either a bad reference pointing to a file not installed on users machines or not using the GAC version of System.Net.Http.

We get the following:
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: The "Microsoft.Web.LibraryManager.Build.RestoreTask" task failed unexpectedly.
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Web.LibraryManager.WebRequestHandler' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.WebRequestHandler..ctor(ProxySettings proxySettings)
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.WebRequestHandler..cctor()
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: --- End of inner exception stack trace ---
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.WebRequestHandler.get_Instance()
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.Providers.Unpkg.UnpkgProvider..ctor(IHostInteraction hostInteraction)
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.Providers.Unpkg.UnpkgProviderFactory.CreateProvider(IHostInteraction hostInteraction)
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.Build.Dependencies.Initialize()
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.Build.Dependencies..ctor(IHostInteraction hostInteraction, IEnumerable`1 assemblyPaths)
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Web.LibraryManager.Build.RestoreTask.Execute()
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>...\packages\Microsoft.Web.LibraryManager.Build.2.0.76\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

Activity

  1. jimmylewis commented on Oct 1, 2019

    @jimmylewis
    Contributor

    Can you try out the 2.0.96 version of the LibraryManager.Build package and see if it addresses the issue? It has a change that might address this (or it might not - we'll see).

  2. senj commented on Oct 2, 2019

    @senj

    I have the same issue:

    The type initializer for 'Microsoft.Web.LibraryManager.WebRequestHandler' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
    

    On hosted VSTS Agent with Visual Studio 2019 it works. Update to 2.0.96 didn't fix it.

    Now I also tested with VSTS Agent with Visual Studio 2017 and it also works there.
    Guess we have to configure something on our build server, but what ..

  3. kant2002 commented on Jan 4, 2020

    @kant2002

    Same with VS2019 and .NET Core 3.1

  4. kant2002 commented on Jan 4, 2020

    @kant2002

    Actually I manage to fix that by specifying --framewok
    Before:

    dotnet build --runtime win7-x64 --configuration Release
    

    After:

    dotnet build --runtime win7-x64 --configuration Release --framework netcoreapp3.1
    
  5. xiwan commented on Apr 26, 2020

    @xiwan

    Actually I manage to fix that by specifying --framewok
    Before:

    dotnet build --runtime win7-x64 --configuration Release
    

    After:

    dotnet build --runtime win7-x64 --configuration Release --framework netcoreapp3.1
    

    Hey kant2002,

    I did as you guide. But the error still there.

    dotnet build --configuration Release --runtime linux-x64 --framework netcoreapp3.1

    PS, the env is within docker.

  6. amoraitis commented on May 3, 2020

    @amoraitis

    Updating to the latest Microsoft.Web.Library.Manager.Build -v 2.1.76 solves that error for me.

  7. added a commit that references this issue on May 12, 2020
  8. jimmylewis commented on Dec 13, 2021

    @jimmylewis
    Contributor

    Seems this was solved in the 2.1.76 package, so resolving the issue.

  9. GeorgeMaharis123 commented on Oct 3, 2022

    @GeorgeMaharis123

    Hi there
    I am still getting these errors with VS 2017 and Microsoft.Web.LibraryManager.Build -v 2.1.175. Could it be possible this bug returned?

    `C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: The "Mi
    crosoft.Web.LibraryManager.Build.RestoreTask" task failed unexpectedly. [C:\Team
    City\buildAgent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: System.
    TypeInitializationException: The type initializer for 'Microsoft.Web.LibraryMana
    ger.Cache.WebRequestHandler' threw an exception. ---> System.TypeInitializationE
    xception: The type initializer for 'Microsoft.Web.LibraryManager.Configuration.S
    ettings' threw an exception. ---> System.IO.FileLoadException: Could not load fi
    le or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyTok
    en=30ad4fe6b2a6aeed'. Could not find or load a specific file. (Exception from HR
    ESULT: 0x80131621) [C:\TeamCity\buildAgent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Configuration.Settings..ctor() [C:\TeamCity\buildAge
    nt\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Configuration.Settings..cctor() [C:\TeamCity\buildAg
    ent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: ---
    End of inner exception stack trace --- [C:\TeamCity\buildAgent\work\bbac78e917f8
    1a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Configuration.ProxySettings.get_Default() [C:\TeamCi
    ty\buildAgent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Cache.WebRequestHandler..cctor() [C:\TeamCity\buildA
    gent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: ---
    End of inner exception stack trace --- [C:\TeamCity\buildAgent\work\bbac78e917f8
    1a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Build.Contracts.Dependencies.Initialize() [C:\TeamCi
    ty\buildAgent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Web.LibraryManager.Build.RestoreTask.Execute() [C:\TeamCity\buildAgent
    work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionH
    ost.Execute() [C:\TeamCity\buildAgent\work\bbac78e917f81a30\Source...]

    C:\Users\teamcitybuild.nuget\packages\microsoft.web.librarymanager.build\2.1.17
    5\build\Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: at M
    icrosoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost ta
    skExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemB
    ucket bucket, TaskExecutionMode howToExecuteTask) [C:\TeamCity\buildAgent\work\b
    bac78e917f81a30\Source...]`

  10. NewToScripting commented on Nov 3, 2022

    @NewToScripting

    In case anyone is facing this issue, what worked for me is deleting the .packages folder at the solution level for the nuget packages referenced. Then I restored the nuget packages and everything built again.

  11. kibblewhite commented on Mar 19, 2025

    @kibblewhite

    2025 and still fighting with this one

    $ dotnet build FullCalendar -c ${ci_commit_ref_slug}
      Determining projects to restore...
      Restored /builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj (in 802 ms).
      2 of 3 projects are up-to-date for restore.
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: The "Microsoft.Web.LibraryManager.Build.RestoreTask" task failed unexpectedly. [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Web.LibraryManager.Build.RestoreTask.PopulateFilesWritten(IEnumerable`1 results, IHostInteraction hostInteraction) [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Web.LibraryManager.Build.RestoreTask.Execute() [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    Build FAILED.
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: The "Microsoft.Web.LibraryManager.Build.RestoreTask" task failed unexpectedly. [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object. [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Web.LibraryManager.Build.RestoreTask.PopulateFilesWritten(IEnumerable`1 results, IHostInteraction hostInteraction) [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Web.LibraryManager.Build.RestoreTask.Execute() [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
    /root/.nuget/packages/microsoft.web.librarymanager.build/3.0.67/build/Microsoft.Web.LibraryManager.Build.targets(35,9): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/builds/byteloch-shared/libraries/blazor-fullcalendar/FullCalendar/FullCalendar.csproj]
        0 Warning(s)
        1 Error(s)
    Time Elapsed 00:00:04.78
    Cleaning up project directory and file based variables
    

    To resolve it I have Downgraded Microsoft.Web.LibraryManager.Build from 3.0.67 to 2.1.175.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions