Visual Studio-Code is not finding Library - c#

I am setting up a simple console project to connect to a database using a connection string. My problem is the project is NOT finding one of the required libraries at runtime.
When I run the console app the application fails.
I go look at the csproj file to ensure I have added the library. I run the command 'dotnet restore -force'. and it finds the library and reports no errors.
The same code works on other developer machines (Windows laptops) but it does not work on my MAC. I am using NuGet Package Manager and NuGet Gallery to ensure I have installed them correctly. I have uninstalled the libraries and re-installed them. It still does not work.
Have I done something wrong? Any suggestions or recommendations would be helpful.

After a lot of searching I found a work around.
I change the usage from System.Extensions to MicroSoft.Extensions.Configuration. I followed the instructions form this question on how to get the connection string.

Related

Unable to find NuGet packages despite packages being installed NU1101

I created my first C# application recently, and since buying a new computer I cannot get the application to start.
I am receiving 7 of the following errors Error NU1101 Unable to find package Microsoft.VisualStudio.Web.CodeGeneration.Design. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages clesson C:\Users\porkh\Desktop\WERK\Personal\c-lesson\clesson\clesson\clesson.csproj
Each with different packages missing.
Since this was a missing dependencies message I reinstalled visual studio 2019 with C# .net support again, yet I am running into the same error.
On StackOverFlow I read that I need to check my NuGet packages,
Here it shows every package that is "missing" in the error messages as installed.
I have also tried running dotnet run and dotnet restore but I get the same error messages.
I am extremely new to C# so sorry if I have missed the solution in other's answers. Any help you can give me I'd appreciate it.
A link to all of my project files here
In the image it says
Not available in this source
and the package source is set to Offline Packages. My best guess is, switching to an official NuGet Feed in the drop down to the upper right, will solve your problem. You also want to check, if the Nuget source is available (it should).
If not, click the Cog icon, and add it there with the name "Nuget" and the Url https://api.nuget.org/v3/index.json

Dotnet CLI fails building after mv to other directory?

Currently, I'm doing my second day of my first internship at a smaller company where I have to build something in C#. Except from Unity, I've never used C# before so I'm kinda new in using it. I'm currently using it on Linux Ubuntu 20. So forgive me for this most likely beginner question.
I'm using dotnet-sdk to build calling "dotnet clean; dotnet build; dotnet ~/pathToDLL/etc/etc". I've finally got something working now, So I cloned the empty git repository from the company and used the mv command to move my directory with some working code to the git repo. Now, when I try to build it it gives the following errors:
/snap/dotnet-sdk/107/sdk/5.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1004: Assets file '/home/oscar/
Tacho/card_reader/obj/project.assets.json' not found.
Run a NuGet package restore to generate this file.
[/home/oscar/Tacho/card_reader/card_reader.csproj]
It gives more or less the same error twice.
/snap/dotnet-sdk/107/sdk/5.0.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5):
error NETSDK1004: Assets file '/home/oscar/
Tacho/card_reader/obj/project.assets.json' not found.
Run a NuGet package restore to generate this file.
[/home/oscar/Tacho/card_reader/card_reader.csproj]
For most users reading this error, this is probably an easy fix. But as I said, I've zero experience using C# on Linux (or Windows) outside of the context of Unity. So any explanation and fix will be very much appreciated!
Oscar
solved
There was a space somewhere in the directory I copied my working code to. I removed this space (and everything before it) for this question because there was company sensitive information there which my boss didn't want to see end up on the internet. Because of the space (in the git repo name) Linux obviously had errors executing commands. Thanks to everyone for the help.
The error seems to indicate that a NuGet package is missing some files. NuGet is a popular library distribution system that is also built into Visual Studio. Even an empty repository may be referencing the package as a dependency or your own code may be using that it. If you are using Visual Studio you can do the following:
Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages.
In Solution Explorer, right click the solution and select Restore NuGet Packages.
Your company might be using a private NuGet server though, so you will want to make sure you are connected to any VPN services. Also do not be shy about asking a co-worker about this issue. This is likely part of configuring your environment properly and not something you are expected to 'just know' as a new intern.

Predefined type 'System.String' is not defined or imported

I have an MVC5 application which I'm trying to run offline. I installed VS2017 offline but when I try to build the project it throws multiple errors relating to it missing all the .NET assemblies and dlls. When I try to add these assemblies they're not available to be added. Anyone please help.
PS: there's NO internet on the machine.
I also have that problem from time to time. What usually helps is to do a dotnet restore. This is different to running restore from the solution explorer within VS, you have to do it through the command line. In order to execute it, you need to have the .NET Core SDK installed. dotnet restore is usually very good at fixing some project problems such as corrupted .json files that VS creates behind the scenes and I would guess that it is able to repair those files without internet connection, but I haven't tried.
Try cleaning and rebuilding your solution. I had this issue and something went funky with my dll's.
It's obvious omnisharp error same as mine. I changed omnisharp path version from c# extension(c# > unistall > install another version) and reopened to vscode. It worked for my project. All error has gone.

Working with Sqlite.dll error

I am trying to make a small application, working with SQLite. However I am running into problems whose solutions on the Net are horribly outdated and nothing I tried works, currently I feel like I have no idea what I am doing.
My problem:
Can't add a reference to SQLite.dll "A reference to sqlite3.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component."
What I've tried:
As far as I know in order to use SQLite in C# code I need to add a reference to an SQLite.dll. I went to the Downloads page of SQLite and downloaded precompiled binaries for Windows (mainly because I have no idea what any of those things are). That didn't work, searched on the 'Net:
Tried both the x32 and x64 version
Installed "SQLite for Windows Runtime" extension
Installed SQLite tools, included them in PATH variable
The only *.dll I could get going was from a Codeproject example which had a sqliteNet.dll file (I have no idea from where) but that had other problems.
From what I looked for all the information/questions/tutorials about SQLite on the Net are horribly outdated and are no help to me.
Currently I am literally lost and have NO idea why it doesn't work and what I should do, please someone help me!
can you use the nuget package for sqlite "System.Data.SQLite"?
Since you need a wrapper to the c-dll you should try some nuget package that wraps it already.
If you haven't tried this method then you have to test it.
Right Click on your Project
Click on Manage NuGet Packages..
In Browse tab search System.Data.SQLite & select it
On Right side click on Install button
After installing you can use it

failed to remove Microsoft.Bcl.Build.Tasks.dll

I am having an issue with my ASP.NET Web-Api solution where my build agent cannot clean its working directories because the library Microsoft.Bcl.Build.Tasks.dll is still in use by some process so it cannot be deleted. The only things I do in my build agent are to build the solution using standard MSBuild.exe, and then I run a few unit tests using MSTest.exe.
I notice that Microsoft.Bcl.Build version 1.0.14 (the version im using) is listed as a dependency by the Microsoft.Net.Http and also by Microsoft.Bcl libraries.
My workflow in the agent is like this:
clone a git repo to the agent
build the solution using msbuild
test the solution using mstest
some time later, maybe 10 minutes, I try and clean up the current iteration
cleaning of the files fails due to the described error
My question is this:
Does anyone know why is this library in use by some process even after many minutes? Is there a common process on windows that would be using this library in the background? I would use the process manager to find why this file was in use, but these build machines are considered to be production boxes and are nearly impossible to get admin access to.
Thanks in advance for the help!
First delete any usages from processes via a program like LockHunter, then restart VS. It worked for me
If your solution contains custom msbuild targets and those same msbuild targets are in use by another csproj in the same solution, you'll run into a conflict at compile time. Effectively, you'd be trying to compile a part of the compilation process mid-compile and you'll run into these types of file lock errors. The workaround is to split your custom msbuild target project(s) out into a separate solution and build them as-needed. I think you'd need to unload & reload the project that depends on the msbuild targets anytime you rebuild them. Once or twice, I needed to restart VS.
If you didn't add any custom msbuild tasks, you can figure out what is causing the problem by looking at the installed NuGet packages. Right click on your solution and click 'Manage NuGet Packages'. Try to remove Microsoft.Bcl.Build from the Installed packages list. It should fail because something depends on it. Make note of what package depends on it. If the first suggestion didn't help, post back a comment with which packages depend on it and I'll see if I can dig up/remember where else I've seen this before.
This question has more details & links about what Microsoft.Bcl.Build is and what it's used for if you're interested: What does the Microsoft.Bcl.Build NuGet package do?
I just came across the same problem on my gitlab build server which does a git fetch before every build set.
After adding Microsoft.Bcy.Async from nuget to my project, the step after the build failed with warning: failed to remove packages/Microsoft.Bcl.Build.1.0.14/tools/Microsoft.Bcl.Build.Tasks.dll
With LockHunter I identified several msbuild.exe tasks.
With that info I found the solution here on so: https://stackoverflow.com/a/12193759/98491
Long story short: the msbuild processes are kept open to improve performance while building. This can be disabled by setting the environmentvariable MSBUILDDISABLENODEREUSE=1 or passing /nodeReuse:false to your msbuild itself.
That fixed it for me.

Categories

Resources