I installed the Newtonsoft.Json package through terminal on VS Code. On running the command "dotnet run" I get the error message:
"The type or namespace name 'Newtonsoft' could not be found"
together with other associated error messages.
How would I address this issue? Thanks
Try run dotnet build first then dotnet run.
The command depends on the dotnet build command to build the code.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run?tabs=netcore30
Based on John's questions above, I found that my installation may have been faulty, so I used "dotnet add package Newtonsoft.Json" to install Newsoft.
Upon restarting VS Code, I found that the errors had disappeared. My sincerest thanks to everyone here in helping me solve this issue.
Related
I am using VS Code and Unity.
Under the output tab (omnisharp log) I get this error
Starting OmniSharp server at 5/27/2022, 3:16:43 AM
Target: /Users/<my.name>/unity/Test Project 3/Test Project 3.sln
[ERROR] Error: Command failed: dotnet --version
/bin/sh: dotnet: command not found
However, when I go the console, I can run dotnet --version just fine
dotnet --version
6.0.202
I now get the unity console telling me that the print command is invalid, but that error isn't highlighted in vs code.
Update: it seems to work if I open VS Code from the terminal. Doing research, it has something to do with the path. Still unsure why it doesn't normally work.
In your terminal enter: where dotnet
Set this directory for omnisharp.dotnetPath in your VSCode preferences.
.Net SDKs are available at this path in Program Files: C:\Program Files\dotnet\sdk
Do you have this .net SDK path set in your 'Environment Variables' -> 'System variables' -> 'Path'? If not, try that.
I'm having an issue when I try to build my project, I get this error:
'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'
Everything I see about this says to update your nuget package manager, so I updated from VS 2015, to 2017 and that didn't work. I update VS2017 to the latest version, still getting that error when I try to build. I tried setting the build dialog verboisty to Diagnostic, but it did not change the text at all. What else can be causing this, because I'm stumped.
The error is accompanied by this error:
The command ""C:\Users\...\NuGet.exe" pack
"C:\Users\...\Project.csproj"
-Properties "Configuration=Debug;Platform=AnyCPU" -NonInteractive -OutputDirectory "C:\Users\...Debug" -symbols"
exited with code 1.
When I run the command manually in the command prompt, it just gives me the dependency already defined error.
EDIT
This was marked as a possible duplicate. It's not, the 3rd paragraph explains why.
Assembly dependency already defined error
You should update the nuget.exe version to 2.12 and above in the path "C:\Users\...\NuGet.exe".
According to the error message, that should be use old nuget.exe to pack the project with dependency netstandard.
As test, I used the old nuget.exe (2.8.6) to pack project with dependency Newtonsoft.Json 11.0.2 like your command line, I got the same error. To resolve this issue, you need to update the nuget.exe in the folder "C:\Users\...\NuGet.exe".
That is the reason why you already update the Visual Studio 2015 to 2017 and still have this issue, because you still use the old nuget.exe in the command line.
Hope this helps.
I have a project targeting net461 (win7-x64) and netcoreapp2.0 (debian.8-x64).
When I build the project on my desktop everything works great.
Build is done by VS or in command line :
dotnet publish -c "Release" -o "xxxx" -f "net461" -r "win7-x64" xxxxx.csproj
dotnet publish -c "Release" -o "xxxx" -f "netcoreapp2.0" -r "debian.8-x64" xxxxx.csproj
But when it is done by our build server (triggered by Gitlab and runned by the Gitlab Runner in Powershell) everything build correctly in net461 but failed for netcoreapp2.0.
The error seems to be produced by Postsharp.
With the version 5.1.3-alpha I have an error about an assembly not found :
Error PS0264: Cannot find the assembly 'flexcel, version=6.19.0.0, culture=neutral, publickeytoken=cb8f6080e6d5a4d6'. Build your project with detailed verbosity to see the assembly loading log.
=> Weird fact, the case of the assembly is not correct, it is Flexcel, and again, it works well in net461.
So I tried to update Postsharp to 5.1.9-preview and now I have an another error :
POSTSHARP30
Error : [C:\Build\Gitlab\Runner\builds\17fef169\0\xxxx.csproj]
C:\Windows\system32\config\systemprofile.nuget\packages\postsharp\5.1.9-preview\build\PostSharp.targets(340,5): error : The process "C:\Windows\system32\config\systemprofile.nuget\packages\postsharp\5.1.9-preview\build\PostSharp-Tools.exe" failed with exit code 2. [C:\Build\Gitlab\Runner\builds\17fef169\0\xxxx.csproj]
For both versions (5.1.3-alpha and 5.1.9-preview), if I log in the build server and run the dotnet publish command in a console, it works well. The issue happens only when this is done by the CI build process.
Does anyone encountered the same kind of errors ?
Thanks.
Luc
PostSharp does not support building on Linux yet.
I don't know why or how, unbelievable, but without a change it is now working...
Really really strange
I downloaded a c# .net project from git onto ubuntu and installed .net libraries from http://www.mono-project.com/download/#download-lin and also donet core from https://www.microsoft.com/net/core#linuxubuntu.
when I run donet restore, I am getting the following error
/home/ubuntu/DotNetWallet/src/DotNetWallet/DotNetWallet.xproj(8,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/1.0.3/Microsoft/VisualStudio/v14.0/DotNet/Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I guess the problem is with the DotNetWallet.xproj which generally is compatible with visual studio but how can I run it on ubuntu?
So, I
used 'dotnet migrate' ,and then used 'donet restore', it now works fine, but when I run 'donet build', I am getting the following error
FakeData.cs(1,20): error CS0234: The type or namespace name 'KeyManagement' does not exist in the namespace 'DotNetWallet' (are you missing an assembly reference?) [/home/ubuntu/DotNetWallet/src/DotNetWallet/DotNetWallet.csproj]
And, here is the git repo link https://github.com/nopara73/DotNetWallet
Many step are required in order to run this project.
First delete global.json file and then run dotnet migrate and remove the backup directory.
(Optional) In some case you will need to clean the solution. If DotNetWallet.xproj and project.json are still there, remove it and run the twxo following command.
dotnet sln remove src/DotNetWallet/DotNetWallet.xsproj
dotnet sln add src/DotNetWallet/DotNetWallet.csproj
Then, remove the first line (using DotNetWallet.KeyManagement;) from FakeData.cs file. This is an unused using statment. there are no impact to remove it.
Now, you can run dotnet restore, dotnet build then dotnet test.
I have a solution which has a two projects. In the both the projects I have packages.config file which has the list of packages that the project uses. Whenever I build the solution I'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 3.**
(replaced folder path with **)
I have installed all the packages manually using package manager console. The installation is successful. When I build the solution now i'm getting the below error
The command "*\Tools\nuget install \packages.config -o \Packages" exited with code 1.**
I have cleared the cache of packages. Still I get this error. Not sure why the solution build is trying to install the packages.
You can try adding -verbosity detailed to your command *\Tools\nuget install \packages.config -o \Packages to get detailed error message to help you investigate the cause.
This was happening in a new CI build I set up yesterday. The problem was that NuGet.exe wasn't at the specified path.
"exited with code 3." wasn't an error from NuGet.exe but from MSBuild.
If you were using TFS, be sure to include the location of the Nuget package in the Source Settings of build definition. This error can indicate it cannot access the files.