Dockertools: PrepareForLaunch task is unable to find Newtonsoft.Json assembly

Created on 4 May 2020  路  9Comments  路  Source: microsoft/DockerTools

When I run docker-compose project via Ctrl+F5, PrepareForLaunch task often fails with the error:
Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies

The error can be fixed by copying the corresponding assembly to C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuildSdks\Microsoft.Docker.Sdk\tools

Visual Studio Enterprise 2019
Version 16.5.4

Most helpful comment

I got the error mentioned in the original post because my docker-compose.override.yaml had a tab (\t) in it.

I ran docker-compose down outside of visual studio and found the issue. Once I replaced the tab with spaces, debugging in visual studio resumed working.

> docker-compose down
ERROR: yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
  in ".\docker-compose.override.yml", line 5, column 1

Hopefully this helps someone else running into a similar issue.

All 9 comments

Something that worked for me was:

  1. stop all the containers that are running. You can check if it's still running with docker ps. And remove them with docker rm -f
  2. clean and then build solution
  3. now run debug

@47th, I am having the same issue. Running VS2019 Enterprise v16.6.2
Where did you get the correct assembly from? V9.0.0.0 is not available on nuget.
9.0.1.0 is. Which runtime dll did you use? There are folders for multiple runtimes.
Thx

@mccjul solution does not work as I have no containers running.

@undecided2013 V9.0.0.0 is the assembly version, which may not match the package version on nuget. Package 9.0.1.0 contains this assembly version and works fine. I used the library for net45

Be aware that it's a hack and it may stop working after a Visual studio update.

@47th , thank you, the 9.0.1 net45 dll workaround worked.

I got the error mentioned in the original post because my docker-compose.override.yaml had a tab (\t) in it.

I ran docker-compose down outside of visual studio and found the issue. Once I replaced the tab with spaces, debugging in visual studio resumed working.

> docker-compose down
ERROR: yaml.scanner.ScannerError: while scanning for the next token
found character '\t' that cannot start any token
  in ".\docker-compose.override.yml", line 5, column 1

Hopefully this helps someone else running into a similar issue.

@47th , thx!
Workaround working for me as well:

  • Copy Newtonsoft.Json.dll (v 9.0.1) to c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise(or other)\MSBuildSdks\Microsoft.Docker.Sdk\tools\

You get this error as well if you are trying to follow the commands in the documentation:
https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019
Quoting from another issue i raised:
I'm hoping to be able to build the same container image like Visual studio uses to debug a visual studio project.
I know how i can build a normal docker image, out of the Dockerfile that visual studio added, so that is not my question.

Following the instruction on this page i think I'm supposed to run:

msbuild /p:SolutionPath=<solution-name>.sln /p:Configuration=Release docker-compose.dcproj

this though gives the following error:

Microsoft (R) Build Engine version 16.8.2+25e4d540b for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10/12/2020 09:36:03.
Project "{...}\docker-compose.dcproj" on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.Visual
Studio.Docker.Compose.targets(202,5): error MSB4018: The "GetServiceReferences" task failed unexpectedly. [{...}\docker-compose.dcproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.Visual
Studio.Docker.Compose.targets(202,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly '
Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The sys
tem cannot find the file specified. [{...}\docker-compose.dcproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.Visual
Studio.Docker.Compose.targets(202,5): error MSB4018: File name: 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, Pub
licKeyToken=30ad4fe6b2a6aeed' [{...}\docker-compose.dcproj]

https://github.com/MicrosoftDocs/visualstudio-docs/issues/6194

For me, the problem was actually that my docker build failed. I could only see this by going to the build output. Once I cleared up the issues there, the error went away.

This issue is fixed in the latest preview version (VS 16.10 Preview 3) by packaging the Newtonsoft.json.dll in the Microsoft.Docker.Sdk.
You can continue to follow the workaround of copying the Newtonsoft.Json.dll to c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise(or other)\MSBuildSdks\Microsoft.Docker.Sdk\tools\ until the fix is in the release channel. Also note that this assembly will get loaded only under certain error cases, so if your build/debug didn't have any error, then you will not run into this assembly load error.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FWest98 picture FWest98  路  5Comments

tanaka-takayoshi picture tanaka-takayoshi  路  5Comments

steveoh picture steveoh  路  4Comments

MichaelSimons picture MichaelSimons  路  4Comments

christiansparre picture christiansparre  路  5Comments