microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

"Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken" when starting docker compose debug with a function app project #421

Open ggirard07 opened 4 months ago

ggirard07 commented 4 months ago

Hi all, not sure what is going on but I am getting this weird in a dialog form when I try to run my docker-compose solution with the debug enabled on an Azure function project in my solution. It used to work properly in the past. I updated Visual Studio and Docker Desktop a couple of times this the last time I touched this solution. image

I am not able to reproduce on a fresh solution. Running with the Azure function project as startup instead of docker compose, directly on the host, is running as expected. Running with the Azure function project as startup instead of docker compose, within its own Docker container, has the same issue with a slightly different dialog. image

I tried to update the build and run verbosity to diagnostic but I am not able to find any useful information (error is happening after the build is done ========== Build completed at X:XX PM and took XX.XXX seconds ==========). There is no useful information in Container Tools or Debug output panes. The debug container is running in Docker Desktop but does not contain any log at that point yet. I tried to get rid of all the obj/bin/.vs folders and also %LocalAppData%/vsdbg, %LocalAppData%/onecoremsvsmon and %LocalAppData%/\AzureFunctionsTools.

What should I do from that point to investigate the issue further? As I am currently not able to tie up this error dialog to the docker tools or azure functions core tools or either Visual Studio itself...

Docker Desktop v4.27.2 Microsoft Visual Studio Professional v17.9.0

NCarlsonMSFT commented 4 months ago

@ggirard07 Based on code inspection I suspect we are failing to parse your local.settings.json file. Would you be able to provide a redacted version of the file so I can see its structure?

ggirard07 commented 4 months ago

@NCarlsonMSFT this file and the host.json one where the 2 I initially suspected for this issue. I already tried to comment/remove most/all of their content but issue still persist. I also tried to replace their content with the content from the same files created by the fresh solution (the one working as expected I mentioned in my initial post) but issue also still persist.

I tried to disable most of the projects in the solution, except the function app. The container tools output is down to the following output when the error occurs:

docker exec -i fa4b865aa707 /bin/sh -c "if PID=$(pidof dotnet); then kill -9 $PID; fi; if PID1=$(pidof func); then kill -9 $PID1; fi"
========== Debugging ==========
docker ps --filter "status=running" --filter "label=com.docker.compose.service" --filter "name=^/My.Functions$" --format {{.ID}} -n 1
fa4b865aa707
NCarlsonMSFT commented 4 months ago

@ggirard07 I was able to repro this error dialog by adding a complex object in the values property which is not supported per local-settings-file can you verify that your local.settings.json only has string key value pairs for the values?

ggirard07 commented 4 months ago

@NCarlsonMSFT I had just keys/values pair, except for the Values but just as the default template. Here is the file content I am currently using, straight from the default template, which still reproduce the issue.

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}
ggirard07 commented 4 months ago

Dam it, I saw the light right after publishing my previous message: I have user secrets in this project! My user secrets indeed contain complex objects! After emptying the user secret file, the issue is gone. I will try to write it as key/value pair for now as I think it is supported too (not totally sure though....). But that stuff used to work, Am I being crazy here? Is it a regression in recent Visual Studio or Docker Tools version?

NCarlsonMSFT commented 4 months ago

Looks like you can flatten it: https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-8.0&tabs=windows#json-structure-flattening-in-visual-studio

ggirard07 commented 4 months ago

Thanks I will try the workaround. But this looks like a regression. Other people on my team still on Visual Studio v17.8.x are not impacted. Also note I have the same kind of user secrets (with objects) for web api projects (so no functions) in same solution which are still working fine. This issue impacts solely my function app project in my solution.

NCarlsonMSFT commented 4 months ago

Yes this is a regression from our adding support for fixing connections strings for the local emulator in user secrets.

dbreshears commented 4 months ago

This should be fixed in 17.10 Preview 3.