Visual Studio 2019 C# Docker debugging process attach error - c#

I'm trying to debug a Linux container that runs a C#/.NET 6.0 console application from Visual Studio 2019 (version 16.11.10).
When I use Debug / Attach to Process... to connect to my running container and attach to my process, I get the error:
Failed to launch debug adapter. Additional information may be available in the output window.
Unable to find debugger script at '/home/dockeruser/.vs-debugger'
For company security purposes, I'm running my container workloads as user dockeruser, but I can reproduce this when I adjust my Dockerfile to run as user root. The error message changes into
Unable to find debugger script at '/root/.vs-debugger'
Output shows
Unable to find debugger script at '/home/dockeruser/.vs-debugger'.
Initialization log:
Determining user folder on remote system...
Checking for existing installation of debugging tools...
Downloading debugger launcher...
Creating debugger installation folder: /home/dockeruser/.vs-debugger
Copying debugger launcher to /home/dockeruser/.vs-debugger/GetVsDbg.sh
Failed: Failed to copy files.
Unable to find debugger script at '/home/dockeruser/.vs-debugger'.
Failed: Unable to find debugger script at '/home/dockeruser/.vs-debugger'.
The program '[1] dotnet' has exited with code -1 (0xffffffff).
I can work around this by docker exec'ing a bash session on my container and running GetDbgVs.sh as detailed in https://stackoverflow.com/a/68950674/17273131, but its a pain to do - it feels like something is misconfigured.
I've already verified that my windows identity is a member of the windows docker-users group.

While not the answer I wanted, I've got a 1-liner shell workaround that I execute on my container when I want to debug attach with VS2019, once I know my <CONTAINER_NAME>. This may be useful to others with this problem.
docker exec -u root <CONTAINER_NAME> sh -c "apt-get update && apt-get install wget -y"; docker exec <CONTAINER_NAME> sh -c "mkdir -p ~/.vs-debugger; wget https://aka.ms/getvsdbgsh -O ~/.vs-debugger/GetVsDbg.sh; chmod a+x ~/.vs-debugger/GetVsDbg.sh"
The first command installs wget as root
The second command downloads GetVsDbg.sh to ~/.vs-debugger

Related

Unable to obtain lock file access (Dotnet CLI)

I use Dev Containers to attach to a container and debug. And it was working just fine.
Recently however it shows this error when I hit F5 or run dotnet build from VS Code's terminal:
/usr/share/dotnet/sdk/7.0.102/NuGet.targets(132,5): error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/fcd2970c0c875310ff5855562ac5f3954170bddb' for operations on '/Crm/AdminApi/obj/project.nuget.cache'. This may mean that a different user or administrator is holding this lock and that this process does not have permission to access it. If no other process is currently performing an operation on this file it may mean that an earlier NuGet process crashed and left an inaccessible lock file, in this case removing the file '/tmp/NuGetScratch/lock/fcd2970c0c875310ff5855562ac5f3954170bddb' will allow NuGet to continue. [/Crm/AdminApi/Api.csproj]
And it shows the above message after trying to re-install every dependency, while NuGet has cached those dependencies already.
It works if:
1- I open a root bash using docker exec -it container_name bash and run dotnet build
2- I open a non root bash, and simply run sudo dotnet build
3- I open a VS Code termianl (which shows vscode as the user) and run sudo dotnet build
I tried sudo chown -R vscode:vscode /tmp/NuGetScratch/ as mentioned in dotnet error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock/ and here, but that did not change anything. I then tried sudo chmod -R 777 /tmp/NuGetScratch and again no results. I even verified that the owner is changed using ls /tmp -lah | grep NuGet and this is the results:
drwxrwxrwx 1 vscode vscode 4.0K Feb 9 10:43 NuGetScratch
What else can I do?
This was recently logged as an issue: https://github.com/NuGet/Home/issues/12420
Possible workarounds listed from https://github.com/NuGet/Home/issues/12420#issuecomment-1423774814:
Run dotnet nuget locals temp -c to clear the /tmp/NuGetScratch (If there is a sticky bit in /tmp permissions then it won't work)
Set environment variable NUGET_ConcurrencyUtils_DeleteOnClose to 1 before running restore, so the lock files will be cleared after restore (This change is only available in NuGet 6.2 and above, probably .NET 7 preview6 and above)
Set environment variable NUGET_SCRATCH to a path. This variable will override the default temp folder. But it's only applied to NuGet version 6.2 and later, probably .NET 7 preview6 and above).

The NPM script 'start' exited without indicating that the create-react-app server was listening for requests

I faced with this problem:
The NPM script 'start' exited without indicating that the create-react-app server was listening for requests. The error output was: 'rimraf' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! CallerPanelProject#0.1.0 start: `rimraf ./build && react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the CallerPanelProject#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
))
TSystem.Threading.Tasks.Task<TResult>.GetResultCore(bool waitCompletionNotification)
I had this problem when made the Node SPA app inside ASP .NET Core and tried to perform start node app in the Production mode. In Development mode everything was OK.
This line in Stratup.cs file caused the problem:
spa.UseReactDevelopmentServer(npmScript: "start");
a source of the problem is: in the production mode Node app has been bundled already, i.e. it has no package.json and other Node related files, so start request is not possible to do.
A good way to fix that is to put start in to the clause:
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
You might have missed installing the dependencies in your source project. That is why it is unable to start to run your application without references.
Run npm install in your source project would resolve the issue
I ran into this problem, after starting afresh with Visual Studio 2019 after a longer break from it (so prette clean setup). It happened when I just tried to set up the simplest ASP.NET Core app, these are the steps I followed / roughly:
Check logs in "Event Viewer" for your app - there I found
"Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found."
Went into Visual Studio Installer (Visual Studio | Tools | Get Tools and Features).
Select the "Individual Components" tab.
Check all (applicable) modules under .NET for ".NET Core .."-anything (I took them all).
Hit "Install while loading"
Restart Visual Studio.
Voila: ASP.NET core app started without errors.
I solved my problem by running "npm install rimraf" in the project folder.
A similar error as #JamesPoulose but I had installed npm. The problem was I installed it when Visual Studio was open. Event Viewer therefore showed me this error:
Category: Microsoft.AspNetCore.SpaServices
EventId: 0
'npm' is not recognized as an internal or external command,
A simple restart of Visual Studio fixed it.
In my case, it was a very silly problem. After re-installing my Windows, I missed installing npm altogether and then running npm install.
My colleague, Dave Wilson, fixed this for me. Went to our react project folder and deleted the node_modules. Next went to the command prompt and npm i in the project folder. Checked the output of npm i and saw that Python was not installed when the module fibres has a dependency on it. Installed python and added it to PATH in system variables. The key thing is to check the output of npm i.
I ran into this issue when Selecting HTTPS instead of HTTP. When running it on your localhost. Inside your visual studio project: Properties/launchSettings.json, change "applicationULR" to route to http instead of https(see image)
settings change

dotnet-sonarscanner - fails on post-processing - "Could not find or load main class"

trying to get the sonar scanner running from the command line at the moment with just msbuild.exe solution.sln /rebuild it's currently failing on the post-processing step and i can't seem to get beyond that
my java path is set in: C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe. I tried updating my path to a location that didn't have any spaces in it but no luck.
I also tried using dotnet sonar scanner and msbuild sonar scanner. both with the same result
These are the steps i'm executing:
dotnet-sonarscanner begin /k:"key" /d:sonar.host.url="https://my_company_sonarqube.com" /d:sonar.login="token" /d:sonar.verbose=true
MSBuild.exe solution.sln /t:Rebuild /p:Platform="Any CPU"
dotnet-sonarscanner end /d:sonar.login="token"
Everything seems to work fine until i get to the post-processing step:
Executing file C:\Users\userid\.dotnet\tools\.store\dotnet-sonarscanner\4.7.1\dotnet-sonarscanner\4.7.1\tools\netcoreapp2.1\any\sonar-scanner-4.1.0.1829\bin\sonar-scanner.bat
Args: -Dsonar.scanAllFiles=true -Dproject.settings=C:\Users\userid\Documents\project_path\.sonarqube\out\sonar-project.properties --embedded --debug <sensitive data removed>
Working directory: C:\Users\userid\Documents\project_path
Timeout (ms):-1
Process id: 38116
Error: Could not find or load main class
Process returned exit code 1
The SonarQube Scanner did not complete successfully
19:53:44.155 Post-processing failed. Exit code: 1
Using the following JDK
java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
ok so i'm not sure why i was getting the main class error. I re-ran everything using the sonarscanner batch script and then with a stripped down java call from the batch script and it seems like my problem was not having my ssl certificates for the sonarqube server.
Starting over and setting SONAR_SCANNER_OPTS seemed to do the trick.
set SONAR_SCANNER_OPTS = "-Djavax.net.ssl.trustStore="C:\path\to\trustStore"

Absolute path in dotnet watch run command doesn't work

To run dotnet core application with specified absolute path we need to run following command:
dotnet run -p C:\foo\bar\Project\Project.csproj
But it seems it doesn't work the same with dotnet watch run:
watch : Could not find a MSBuild project file in 'C:\directory\where\we\execute\command'. Specify which project to use with the --project option.
Running the same command with -project instead of -p doesn't help however...
Dotnet watch help specifies -p or -project parameter anyway:
Microsoft DotNet File Watcher 2.1.1-rtm-30846
Usage: dotnet watch [options] [[--] ...]
Options: -?|-h|--help Show help information
-p|--project The project to watch -q|--quiet Suppresses all output except warnings and errors -v|--verbose
Show verbose output --list Lists all discovered
files without starting the watcher --version Show
version information
Environment variables:
DOTNET_USE_POLLING_FILE_WATCHER When set to '1' or 'true',
dotnet-watch will poll the file system for changes. This is required
for some file systems, such as network shares, Docker mounted
volumes, and other virtual file systems.
DOTNET_WATCH dotnet-watch sets this variable to '1' on all child
processes launched.
Remarks: The special option '--' is used to delimit the end of the
options and the beginning of arguments that will be passed to the
child dotnet process. Its use is optional. When the special option
'--' is not used, dotnet-watch will use the first unrecognized
argument as the beginning of all arguments passed into the child
dotnet process.
For example: dotnet watch -- --verbose run
Even though '--verbose' is an option dotnet-watch supports, the use
of '--' indicates that '--verbose' should be treated instead as an
argument for dotnet-run.
Examples: dotnet watch run dotnet watch test
What's wrong then? Why absolute path to project doesn't work with dotnet watch run while works with dotnet run?
You can resolve this by specifying the -p (or the longer --project) option on the watch command rather than on the run command. In your case, that would be:
dotnet watch -p C:\foo\bar\Project\Project.csproj run
There's a note in the docs that covers this:
You can use dotnet watch --project <PROJECT> to specify a project to watch. For example, running dotnet watch --project WebApp run from the root of the sample app will also run and watch the WebApp project.
I'm not 100% sure, but dotnet watch is looking for file changes in the current directory. So if you use absolute path it must know where should it looks for changes. Of course, such implementation is possible but I just think that nobody thinked about it when implementing watch command
In my case, its just a minor error, you have to enter in the project directory before executing dotnet command, like:
cd yourAppName
dotnet watch run
It'll run

Unable to set the current stack frame

I opened the command window in Visual Studio 2015 CTP and given the following command
>k ef migration add [migration name]
>k ef migration apply
It is giving the response message as Unable to set the current stack frame.
How to solve the above issue.
I am Scaffolding a new migration for the pending model changes and applying them to the database from the command line.
I am following on View components and Inject in ASP.NET MVC 6
In an administrator command window, change the directory to the project directory. The project directory contains the project.json file.
Then run the commands from there.
So in short, don't use the visual command window, but an actual windows command window.
You should follow these steps to install the K command:
Install the K Version Manager (KVM)
Open a command prompt with Run as administrator.
Run the following command:
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))"
The script installs KVM for the current user.
Exit the command prompt window and start another as an administrator (you need to start a new command prompt to get the updated path environment).
Upgrade KVM with the following command:
KVM upgrade
You are now ready to run EF migrations.
The source is your shared link "View components and Inject in ASP.NET MVC 6"
Than you need to run commands at cmd.exe

Categories

Resources