Visual Studio 2017 C# target framework issue - c#

I recently included a .net 4.6.2 project to use with my .net core 2.1 app. But after I've done this the projects stopped to compile throwing this error:
Error Your project does not reference ".NETFramework,Version=v4.6.2"
framework. Add a reference to ".NETFramework,Version=v4.6.2" in the
"TargetFrameworks" property of your project file and then re-run NuGet
restore. SelfSignCertificateAssistant
The project stopped to compile even for another pure 4.6.2 solution. Needless to say it was working just fine before.
There was absolutely nothing that was changed in the project, so I'm not sure how to fix this:

As i figured in most cases solution proposed by #Chris should work. But for some unknown reason my Visual Studio just refused to compile it throwing the same error. I tried to re-download the project, re-reference frameworks, restarting VS...
What helped me is physically deleting project folder and then re-downloading it from source control. After this was done i was able to successfully compile it. Not sure what was the problem though.

In Visual Studio go to Tools > Options... and in the left pane, scroll down and select Nuget Package Manager. Then, check the boxes under General that say "Allow nuget to download missing packages" and "Automatically check for missing packages during build in Visual Studio".
Once you do that, try rebuilding your project and nuget should then restore any missing packages for your project.

Related

GetPathsOfAllDirectoriesAbove() cannot be evaluated after updating .Net Framework version (4.6.2 to 4.7.2)

A project I have been working on was upgraded from .NET Framework 4.6.2 to 4.7.2.
On build, in a file that is not my code, I get the following error:
I also see the same error in the build tab of my project properties.
I'm at a loss- I've searched for the error and am coming up empty. Has anyone encountered and/or resolved this before?
Looks like after upgrading your build tool is changed from MSBUILD to Roslyn. Microsoft.Managed.Core.targets is Roslyn target file.
if you have following Nuget packages installed:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
Then possibly it's causing the issue. Upgrade the Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 2.x and remove the second one. That should fix the issue.
Ran into the same error - a compatibility issue between Microsoft.Net.Compilers 2.x (vs2017) and 3.x (vs2019) - downgrading from v3 to v2 fixed the issue specifically on our build agents which only had VS2017. v3 requires VS 2019 or later per roslyn-analyzers release spec.
Per the related error Method 'System.String.GetPathsOfAllDirectoriesAbove' not found - VS2017 would not even open the CSPROJ which was a clue about compatibility.
VS 2017 - CSPROJ Option to Install Missing Features for Microsoft.Net.Compilers v3
VS 2017 - Installing Missing Features
This happned to me when I updated Microsoft.Net.Compilers in an old project.
Removing Microsoft.Net.Compilers completely, and then updating Microsoft.CodeDom.Providers.DotNetCompilerPlatform resolved my problem.
This can also happen when trying to compile a VS2019 project with an older version of Visual Studio (e.g., on a build server or in Azure DevOps).
If, after applying the solution from answer https://stackoverflow.com/a/59276492/2279059, the error changes to
##[error]CSC(0,0): Error CS1617: Invalid option '8.0' for /langversion
then this is likely the case. The solution is then to build with the right version of Visual Studio (2019).
This error usually comes when you upgrade the below libraries by nuget
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Microsoft.Net.Compilers
Guys, If your project is not loading due to this error. just go to that project location by explorer and delete the obj folder manually.
Then right-click on the project and RELOAD AGAIN.

Why is Referenced Component not be found in Visual Studio 2017 when it is found in Visual Studio 2015

I have a solution with two projects - a primary project, and a unit test project. When opening in Visual Studio 2015 all references are found and project builds successfully. When opening in Visual Studio 2017 several but not all NuGet package references are not found and compile fails. Some of the failed references are...
System.Data.Common
System.Net.Http
System.Net.Http.WebRequest
System.Security.Cryptography.Algorithms
System.Security.Cryptography.Encoding
System.Security.Cryptography.Primitives
System.Security.Cryptography.X509Certificates
... but other NuGet references are found with no problem. This solution was created with VS2015. When viewing the .csproj file nothing out of the ordinary is jumping out.
I am thinking of rebuilding it from scratch in VS2017 to try to identify the problem.
Has anyone else experienced this problem, and/or has anyone any suggestions on why this is occurring and what should be done to facilitate a fix?
Update:
I created a brand new VS2017 WebApi project referencing .NET 4.7.1, and compiled successfully. I then added NuGet package System.Data.Common 4.3.0. The NuGet install process appears to have completed with no errors, but still I am left with an invalid reference. That was pretty easy to replicate.
OK, answering my own question.
I found what I believe is the answer. This particular project was originally developed in VS2015 using .NET 4.6.2. When changing to VS2017 we elected to upgrade .NET to 4.7.1. The problem is with the .NET version, not the VS version.
The newer version of .NET has many of these NuGet assemblies added to standard libraries. The NuGet packages were in conflict with the native .NET 4.7.1 namespaces. For example, in .NET 4.7.1, the namespace System.Data.Common is found in the assembly System.Data.dll. No longer is it required to add a NuGet assembly System.Data.Common.dll. In fact, if I do add System.Data.Common NuGet package assembly, I now have two assemblies having the namespace System.Data.Common - one in System.Data.dll and another in System.Data.Common.dll - hence the reference problem.
The solution is to use the .NET 4.7.1 version and remove the extra NuGet assembly. This was also true for System.Security conflicts. The conflict with System.Net.Http was actually moved into a NuGet assembly called Microsoft.AspNet.WebApi.Client.
I hope all of this helps someone else...(uhhhgggg)....
BTW - it appears that when using VS2015 with .NET 4.7.1, these conflicts are suppressed and never display. This feels like a shortcoming of VS2015. Glad VS2017 shows them to reveal the true problem...
Check your packages.config file to make sure the Nuget packages are actually listed as dependencies for your project.
Also, open the solution in VS 2015 and double check the file path for the references in question. Make sure the DLLs are not referenced from a file path unique to Visual Studio 2015.
I had to create a new project and transfer all the necessary files from the old project to new project to fix this.

How to use C# dll in F# project? Getting yellow triangle with an exclamation mark [duplicate]

I wish to test the core class of a plugin by directly referencing the plugin project and instantiating the plugin class. When I create a test Console App project and add a project reference to the plugin project, I get a warning icon (yellow triangle with exclamation mark) next to the reference in the References list.
When I instead add a reference to the dll, the assembly build output of the plugin, I get no such warning. What could this warning be trying to tell me?
As mentioned in the question's comments, differing .NET Framework versions between the projects can cause this. Check your new project's properties to ensure that a different default version isn't being used.
Encountered the same issue with a ASP.Net Web App and two library class projects which needed to be referenced within the Web App. I had no information provided on why the build failed and the references were invalid.
Solution was to ensure all projects had the same Target Framework:
In Visual Studio 2015- Right Click project > Properties > Application > Target Framework
Save, Clean and Rebuild solution. The project references should no longer appear as yellow warnings and the solution will compile.
My Web App was targeting .Net 4.5 whereas the other two dependent library class projects targeted .Net v4.5.2
Make sure all versions are same for each projects click each projects and see the version here Project > Properties > Application > Target .NET framework
a. Go to Tools > Nuget Package Manager > Package Manager Console Type Update-Package -Reinstall (if not working proceed to 2.b)
b. THIS IS CRITICAL BUT THE BIGGEST POSSIBILITY THAT WILL WORK. Remove < Target > Maybe with multiple lines < /Target > usually found at the bottom part of .csproj.
Save, load and build the solution.
For both of (or all of) the projects that you want to use together:
Right click on the project > Properties > Application > Target .NET framework
Make sure that both of (or all of) your projects are using the same .NET framework version.
Reinstall all packages in all projects of the current solution:
Update-Package -Reinstall
Try closing and opening VS.
Seems silly but after 1 hour of following the above and finding everything lined up OK. I restarted VS 2017 and the problems were gone.
Make sure you have the projects targeting the same framework version. Most of the times the reason would be that current project ( where you are adding reference of another project ) points to a different .net framework version than the rest ones.
For me, I ran into this issue when referencing a .NET Standard 2.0 class library in a .NET Framework 4.7.1 console application. Yes, the frameworks are different, but they are compatible (.NET Standard is supposed to jive with both .NET Core and .NET Framework.) I tried cleaning, rebuilding, removing and readding the project reference, etc... with no success. Finally, quitting Visual Studio and reopening resolved the issue.
Check NETFramework of the referred dll & the Project where you are adding the DLL.
Ex:
DLL ==> supportedRuntime version="v4.0"
Project ==> supportedRuntime version="v3.0"
You will get warning icon.
Solution : Make dll version consistence across.
It's been a long time since this question was asked but if someone is still interested - I recently ran into similar icons. I was compiling a C#.net project using VS 2008. I found VS could not locate the assemblies for those references. When I double clicked VS refreshed the references and removed the icons on some of those[EDIT: which it could NOW locate]. For remaining references, I had to compile the respective assemblies.
Adding my 2 cents to the #kad81 answer,
Go to Visual Studio -> BUILD -> Configuration Manager
In the "Active Solution Platform" drop down in top right hand corner (mine is VS 2012), if it is "Mixed Platforms", change it to the appropriate platform based upon your reference third party assemblies.
Then in each of the project in the list, make sure you select same platform for all the project. (if x86 not exist, then select "", then you can select "x86".)
Rebuild the library projects first and then referencing projects.
Hope this helps.
In Asp.net core sometime it shows alert if you changes the project name space or name. To remove this kind of alerts you just Unload Project and load it again.
If issue is still there means you it can not find your Assembly reference.
Using Visual Studio 2019 with all projects targeting .Net Core 3.1 the solution was to:
Clean / Build / Rebuild.
Restart Visual Studio 2019
Also happens if you explicitly reference a project that was already implicitly referenced.
i.e
project a references project b
project c references project a (which adds implicit ref. Expand and see)
project c references project b
you will see an exclamation mark next to b under project references.
I had these icons for a different reason. We have one big solution for all our projects (nearly 100). I made a subselection of the projects I was interested in and made a new solution. However the references where project references instead of references to the compiled dll's....
After some research I found this link on GitHub which explains this is new behaviour in VS2015.
On the GitHub page they explain a workaround for converting project references to binary references.
To fix some not working stuff it has sense to remove some libraries sometimes, how would not that sound weird.
Anyways, I believe the problem is too wide and might be caused by different factors, so want to share my situation/solution.
I had a project (brought by customer) with Xamarin Forms and Telerik libraries. The thing was in general related to the components, which libraries are not included into packages folder, nor available via Nuget (paid ones).
The whole project References were "yellow", it looked horribly and scary.
The solution was just to remove those Telerik references (including a few controls in code which were using that). Right after that all the references magically got their common normal grey color and the errors (mostly) disappeared.
"Mostly" - because "all red around" error messages about "the element is not defined anywhere" sometimes happen still. That's weird, and brings inconvenience, but I still able to compile and run the project(s): just need to clean solution, restart Visual Studio, pray a little bit, clean again, remove obj/bin folders, restart again, and it works well.
The key thing is remove not available libraries references, as the error messages say absolutely another stuff. (For instance, something like "Xamarin.Build.Download.XamarinDownloadArchives not found or cannot find something" etc., but that just might mean you don't have some references available.
Then remove packages folder, reload/reopen the project/solution, go to "Manage Nuget Packages" and click "Restore" button.
In a multi-project solution, If every other thing failed... On the startUp project, check.
Dependencies->Assemblies and see if the erring referenced project is there. Remove it and re-build.
I had the same issue in a solution with projects targting .NET Core 3.1, .NET Standard 2.0 and .NET Framework 4.8. The issue was on this last one.
The trick that solved the issue for me, was to change the target framework to .NET Framework 4.5, then back to .NET Framework 4.8.
I have absolutely no idea why this fixed the issue, but it did.
The IDE was Visual Studio 2019.
Open the YOURPROJECT.csproj file with a text editor then at the end of the file remove these lines inside the target tag, and then build the project again!
be sure the Package folder is in the correct path which mentioned in < Reference > < HintPath >
<Error Condition="!Exists('.......
Enjoy it ;)
I also faced the same problem but my case was a bit different the ones above. I tried to open a project created in a different computer. I found that the path to package folder is not updated when you add a reference so restarting VS, changing .NET version, or any mentioned recommendation does not solve the problem. I opened the csproj file in notepad++ and corrected all the relative paths to packages folder. Then; all the warnings are gone. Hope it helps.
in VS 2017 Do a Clean then Build
Thank you all for the help. Here is a breakdown of how I fixed my problem:
Right click on your project > Properties
Under Application change the target Framework. In my case ImageSharp was using .Net 4.6.1. You can find this in your packages.config.
Go to your project references. You'll notice SixLabors has a yellow triangle. You have to update the NuGet package.
Right click on References > Manage NuGet Packages.
Update SixLabors.
You might have slight code updates (see below) but this fixed my problem.
Convert ImageSharp.Image to ImageSharp.PixelFormats.Rgba32?
In Visual Studio 2019, one of my projects target framework was .net core but it was referencing another project whose target framework was .net standard. I changed all of the projects to reference .net standard and the icons went away. To see what your project is right click it and click properties and look at Target framework. You can also normal click the project itself and look at the < TargetFramework > tag under < PropertyGroup >
I had created a new .sln which was put in a subfolder. The .nuget folder was missing from where that .sln file was added. Moving the .nuget folder from the root into the subfolder where my new .sln file was solved the issue for me.
I came back later and added the .sln file to the root and deleted the subfolder. Doing this originally would have solved the issue as well.
Based on the answer from #AljohnYamaro (sorry, couldn't comment on your answer, new account without enough reputation yet, but upvotaded you), I've checked the .csproj file.
On my file, besides the standard project reference:
<ProjectReference Include="..\ProjectA\ProjectA.csproj">
<Private>true</Private>
<CopyLocalSatelliteAssemblies>true</CopyLocalSatelliteAssemblies>
</ProjectReference>
There were also a directy link to the compiled dll from the referenced project:
<ItemGroup>
<Reference Include="ProjectA">
<HintPath>..\ProjectA\bin\Debug\netcoreapp3.1\ProjectA.dll</HintPath>
</Reference>
</ItemGroup>
Removing this second reference solved the issue.
One of the reasons to get this annoying yellow triangle is that you are adding a reference to a project twice, meaning:
Reference one: MyProjectOne (which contains already a reference to MyProjectTwo)
Reference two: MyProjectTwo
By deleting the Reference two, the yellow triangle will disappear.
If you're using the newer style Sdk projects add OutputType to the ProjectGroup element with a value of Library in the project you're referencing.
It'll also give you grief if it's in the project you're referencing and it references a project without the setting.
find your .csprojc file and open it.
find your packages path. I fixed my project by this issue.
..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
this .. means vs will find this dll in parent directory.
you should confirm your package path, and your will fixed this issue.
one more simple answer : exit visual studio and re-open it, it has solved for my problem.

Nuget version not correct?

I have a project that i cannot compile. When i try to do so I get the following error:
The 'Microsoft.Bcl.Build 1.0.14' package requires NuGet client version '2.8.1' or above, but the current NuGet version is '2.7.41115.310'.
Normally this would be simple. After searching I found this guide:
http://www.daimto.com/package-requires-nuget-client-version-x/
That explains how I can upgrade my Nuget client version. However, when i follow those steps, I find that I am already using the latest version of Nuget: 2.8.5
For some reason however, Visual Studio 2013 Ultimate is using an older version, and I don't understand why.
My install of Visual Studio Ultimate 2013 is a fresh install, after unninstalling Visual Studio for Web Express 2012. The previous version was giving me a considerable amount of problems and so I deleted it and moved on to 2013. I wonder if some cofig files were passed through, but I cant be sure.
How can I fix this problem?
From Tools → Extensions and Updates → Installed, uninstall “NuGet Package Manager” and install it again.
So, after searching around I found no answers, so I decided to look into the project folders. It happens that I have the main version of NuGet.exe, 2.8.5 in main folder, but the project was nowhere near that main folder.
This way, when I downloaded the project it simply used the NuGet version pulled from TFS (or so I assume), and that was the problem - that verison was Nuget.exe 2.7.4.
After replacing the "Nuget.exe" files (found in /.nuget folder of the project) the project finally compiled and everythign started working again.
You can also try update Nuget Package Manager directly from Tools > Extensions and Updates
In my case, a pending update of Visual Studio fixed the nuget version.
The update was the "Update 5" for VisualStudio 2013.
The update was listed under the menu Tools → Extensions and Updates, on the tab Updates.
I was getting this error from a recently cloned branch, but (in contrast to the above solution) found that my Nuget version in the project directory was the same as that in my solution directory.
I solved this by right clicking on the solution and Managing Nuget Packages for the solution. The Nuget dialog that popped up said that packages were missing and asked me to restore them. Once downloaded, the project built successfully.
I had the same issue when trying to install System.Net.Http and it said the nuget version needed to be version 3.0 or above. I tried few things but in the end, used Tools and Manage Nuget Packages and did a search and tried to install it from there when it said exactly the same thing - wrong version of nuget, but it popped up with an upgrade Nuget button too!
Hope this helps someone
Simply reinstall nuget in visual studio

This project cannot be viewed in the object browser because it is unavailable or not yet built

I have a VS2013 solution that has many projects all C# with framework 4.5
When I try and rebuild all projects in the solution I get an error message
This project cannot be viewed in the object browser because it is unavailable or not yet built
I note that in the start up project the references to the other DLLS appear as though the DLLs are missing.
I can actually get the solution to run by building each project one at a time, and then double clicking the reference in the start up project.
Eventually I have gotten rid of all the bad reference icons in the start up project and the solution will run.
However as soon as I rebuild the whole solution the bad references re-appear.
Strangely Build works, but Re-Build doesn't, and Clean and Re-build doesn't.
I do have the following set up.
Project Templates References Project DomainLayer
Project DataLayer References Project Templates and Project DomainLayer
Thus VS needs to build DomainLayer first then Templates then DataLayer.... perhaps it can't work this out?
What is going on?
Although you could build projects individually, but cannot rebuild solution. It sounds to be problem with target framework. Go to project properties and ensure you're targeting Framework 4.5 for all projects. Somewhere in some project this might be missing.
Try uninstalling the NuGet packages, ensuring all of the project references are removed, restarting VS, and installing the packages again. Afterwards, check that the references don't have any warning icons.
My only guess is that this happens due to some type of bug or due to manual modification of project files which causes VS to install and reference NuGet packages incorrectly.
I use vs2019 and have the same problem
My solution:
Upgrade .net framework
Close visual studio
Delete folder packages in solution
Open project again and rebuild solution
Hope useful for you.

Categories

Resources