Problems with adding reference to netstandard 2.0 - c#

I changed my Asp.Net Core 1.1 application to Core 2.0
This went pretty well but after I updated my nuget packages and I get this error everywhere
The type 'xxx' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
When I press the button to add an assembly nothing happens. I tried rebuilding and restoring my packages multiple times but it won't work

I think you are having problem with the reference to the old NETStandard version in your class library.
Just make sure you have removed NETStandard reference from all the csproj files in the solution.

Related

.NET C# - Could not load file or assembly [...] or one of it's dependencies. The system cannot find the file specified

I am trying to use MathNet.Filtering (https://github.com/mathnet/mathnet-filtering) and I receive during runtime the error Could not load the file or assembly 'MathNet.Filtering, Version=0.7.0.0, Culture=neutral, PublicKeyToken=null or one of its dependencies . The system cannot find the file specified. This happens when trying to use any part of the MathNet.Filtering class.
Such as
MathNet.Fitering.OnlineFilter myFilt = MathNet.Filtering.OnlineFilter.CreateBandpass(MathNet.Filtering.ImpulseResponse.Finite, 8000,100,15000,50);
I am already referencing MathNet.Numerics as it is a dependency to MathNet.Filtering.
I am compiling and running with .NET 4.6.1 and the dll for MathNet is built to target .NET 4.6.1.
Using dotPeek I can see there are other dependencies:
MathNet.Numerics (already referenced version 4.9.1.0)
mscorlib
System
System.Core
System.Numerics
System.ValueTuple
[]
I am struggling to see why I am getting Could not load the file or assembly . There are no external references missing.
Is the problem related to System.ValueTuple?
I can use the MathNet.Numerics classes without any issue, this has all the same dependencies except System.ValueTuple
But when I try and explicitly reference System.ValueTuple's DLL I receive
System.ValueTuple exists in both [path to reference] and C:\Windows\[...]\mscorlib.dll
Any ideas what is going on here? Stuck at this for hours
Thanks

.Net Framework You must add a reference to assembly mscorlib, Version=4.0.0.0

After updating and including some NuGet packages, I now get many compile errors similar to:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
I looked at You must add a reference to assembly mscorlib, version=4.0.0 but I'm not running .Net core - this is an ASP.NET MVC, .Net Framework 4.7.2 Project.
There is no project.json to update. I already included the Microsoft.NETCore.Portable.Compatibility NuGet package to no effect.
What is causing this, and how can I fix it?
Right-Click on your project and click Clean Solution in Visual Studio, and then try building it again. Solves the problem most of the time for me.
Or else, in case you copy-pasted a class from somewhere else, try creating a new class in your project and instead, copy-paste the code within the other class instead of just copying the class itself.
I also faced the same issue, I got this when I was trying to install EntityFramework.
Code Clean-Up worked for me. Go to analyze and then try to run code cleanup using both profiles.
For completeness's sake, I'll include the fix that actually worked for me as an answer.
Just delete the repo, re-clone, and try again.

netstandard 2.0 nuget reference results in error CS0012 on TFS build

I've created project_A targeting .NET Standard 2.0 and made a nuget package from it. Its dependencies look as follow:
project_A dependencies
Then this nuget is being used in project_B which results in errors during build (but only on TFS), which are:
error CS0012: The type 'Object' is defined in an assembly that is not
referenced. You must add a reference to assembly 'System.Runtime,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
project_B dependencies
It looks like after deletion of project_A nuget reference in project_B the errors are gone. Adding System.Runtime as nuget to the project_B doesn't fix it.
Thanks in advice for any ideas.

Do I need to modify my existing csproj or add a project.json file to a command project that references a new .net standard library?

I have recently made the decision to try and re-standardise my older style PCL's from the (apparently archaic) old approach of portable-net451+win81+wpa81 to now netstandard1.x. I took this decision as Xamarin Forms on my Mac was no longer recognising one of my libraries as a NuGet package.
Anyway, having started this conversion I have entered a world of unknown pain in the sense that it isn't a very automatic process. I'm now at the stage where I think I've converted my PCL's to net standard libraries but now I'm trying to reference these standards within a 'normal' windows console app I get odd errors.
Primarily my errors are thus:
Error CS0012: The type System.Linq.IQueryable 1<TItem> is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Linq.Expressions, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (CS0012)
Error CS0012: The type System.Collections.IEnumerable is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (CS0012) (Redbridge.Console)
Now given that my project is referencing one of my net standard libraries and this error originates from me using a class that requires packages System.Linq.Queryable and System.Linq to be added specifically to my net standard library I can't help but wonder how I'm meant to make this work in my console app library. I note that the versions are .20 rather than the standard .0 so what do I do to make this work?
I've tried the obvious (referencing the above packages in my console app as suggested by the compiler) but to no effect. Does anyone have any advice? Do I need to add a project.json file for example to my console app so that I can indicate that .NET standard should be used or something?
I've read quite a bit on the .NET standard and like most find it confusing as to what I'm expected to do.

project reference won't compile 'should be reference'

In the following new test project I've created for testing the web code I have the following error when trying to compile my code.
Not sure what this means because I've added the reference to the project including the controllers into the test project??
Any ideas
Many thanks,
James
Error message
Error 330 The type 'Web.Supporting.BaseControllers.PowerController' is defined in an assembly that is not referenced. You must add a reference to assembly 'Web.Areas, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. C:\Power\Test.Unit.Web.Portal\Controllers\SearchProductControllerTests.cs 39 13 Test.Unit.Web.Portal
UPDATE
Tried adding system.web.mvc into the test project although I can't see it, see image below
UPDATE
Found it by looking at an existing test project. Can't see it in the dialog (???) but I located it here: C:..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll
Did you include reference to Web.Areas library which it is asking for? If not add it.
If you already have a reference to it then "Target Framework Version" will be the problem. If your current project is targeted to lesser version than the referenced assemblies this will happen. Ex: If current project targets to .net4.0 and Web.Areas is targeted to .net4.5 this error will appear.
To fix it you may need to downgrade all other projects version or upgrade current project's version.
To resolve this I added a reference into the test project for the PowerController dll and also the system.web.mvc. Note: system.web.mvc is in the extension tab of the 'add reference' dialog.

Categories

Resources