Error CS0012 The type 'Object' 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'. #391
Comments
I believe you are missing a reference to For now you have to manually add a reference to this package which can be annoying, but in the future we are planning on the tooling doing this for you. Let me know if that works for you. |
Hi, |
Looks like NuGet doesn't emit the necessary binding redirects to the .net framework library project since it is both a library and doesn't have an app.config. You could try to add <PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> |
Hi @dasMulli,
to the net461 project but nothing changes. Thanks again |
It is definitely a priority but it is still a work in progress. Until it is complete you need to add the reference to NETStandard.Library.NETFramework into your net461 project. With that I was able to get past this error on your sample project. However I quickly hit an error with the Raven Client nuget package.
Which is because the net45 assembly identity of Raven.Client.Lightweight is different from the netstandard version. The net45 has a PublicKeyToken and the netstandard one doesn't. That appears to be a bug with RavenDB package. |
Hi @weshaggard |
FYI, Not sure if this is related, but perhaps some will find this useful. net461 framework with aspnetcore. Was getting similar exceptions:
This was due to a wrong SDK. Updated to |
Package NETStandard.Library.NETFramework has been deprecated according to this if you have the released .NET Core SDK 2.0 installed. Adding the propertyGroup with settings to generate the binding redirects seems to solve the problem with Visual Studio 2017 (15.3). However, building the same project with msbuild in a script fails with "error CS0012: the type 'Object' 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' " Also, instead of 'Object' it may say 'Action<>' in the error message. Looks as if Visual Studio 2017 is not using the same set of msbuild tools/tasks ad the msbuild you run from the command line. Any suggestion how to confirm the versions either way? |
I am also coming across this issue with VS 2017 15.4 Preview 1, and a UWP project targeted to Windows 10 Build 16267. I have just installed the .NET Standard 2.0.2 SDK to fix an issue with not being able to use the .NET Standard project with a UWP project - but now have run into the above problem. Guessing that means this issue hasn't been completely fixed? |
@ManfredLange What version of msbuild are you using from the command line? Be sure to be running from a VS 2017 dev command prompt.
@daveh101 what do you mean by that SDK? I don't know of any .NET Standard SDK? Are you talking about the .NET Core SDK? If so I don't think there is a 2.0.2 version of that yet. |
@weshaggard https://blogs.msdn.microsoft.com/dotnet/2017/08/25/uwp-net-standard-2-0-preview After doing so, I was still getting an error like this:
In the comments, there is a fix that says .NET Standard SDK 2.0.2 - https://aka.ms/ns2x64 - or - https://aka.ms/ns2x86 Before installing the above it wouldn't even attempt to build. Now, it does try to build but I get the issue this thread. Hope that helps |
@weshaggard Our build script is a powershell script that we run from a regular powershell terminal. The msbuild version we use is the one located at: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0 We haven't use the dev command prompt for many years. Instead we opted for a powershell script that cleans up the environment, builds the solution, deploys the solution (locally or build machine), then executes the test suite and finally reports the result. That approach is working very well across multiple products/companies and has been for several years now. Occasionally, for diagnosing issues we sometimes switch to the one that is located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0 However, the latter is only available on a box with VS 2017 Professional Edition installed. On our build machines we only have the build tools available. This means that when we use the one that comes with VS 2017 Professional, we have 9 target files more. All other files are identical. As per the file properties the file version of msbuild.exe is "15.3.409.57025" and the product version is "15.3.409+gc1de301405". Note that we haven't updated to the preview of VS 2017, 15.4 yet because of lack of time. Meanwhile I observed this: If a ns2.0 assembly uses a net461 nuget package, that's fine (other than a warning if the nuget package does not target netstandard 2.0 or lower). If a ns2.0 project references a net461 project, that is a problem and by the looks of it not a tested scenario for VS 2017 version 15.3. I have not found a solution/workaround for the latter. A net461 project can reference a ns2.0 project without problem. Also a net461 project can make use of the nuget packages we use without issues as usually all of those packages also have a target that works for net461. So it appears that (in our environment) we need to distinguish between nuget packages (work fine so far) and referenced projects (problematic depending on the combination). Note that we have a solution with 50+ projects, so it would be great to be able to mix net461 and ns2,0 projects so that we can incrementally move from net461 to ns2.0. The alternative is not viable for a production system with continuous delivery in my opinion. |
@ManfredLange I'm not actually sure that referencing a net461 project from an ns20 project is fully working/supported. I've not personally tried that direction. I don't know a lot about all the different msbuild and VS tool combinations so I going to suggest you file a new issue at https://github.com/dotnet/project-system as they are the C# VS experts. |
I've installed all the latest updates for the build tools and visual studio, and I also can't build from the command line. from Visual Studio 2017 it works fine. When I build a (very simple) project:
EDIT: I just had an older version of the SDK in my path. Just wondering why this is not updated automatically when you install newer build tools. |
@weshaggard so I'm assuming mixing .net standard 2 with 4.6 is unsupported as well? Perhaps tooling could tell us these things so we're not spending hours digging up GitHub tickets trying to figure out why our projects are exploding with ambiguous errors. |
That is correct. See https://docs.microsoft.com/en-us/dotnet/standard/net-standard for the support matrix. I would have expected the tooling to generally block you from adding references to netstandard2.0 libraries from a .NET 4.6 application but there are likely bugs in various scenarios there. If you are hitting upon one please file an issue at https://github.com/dotnet/project-system. |
@weshaggard Are you thinking of .NET core? The entire point of .NET standard is to be an API between the full framework and core. In fact I'm able to use a mix of .NET standard and framework just fine. If something isn't supported it will simply fail and move on. |
No. You are exactly correct that .NET Standard is the API between Full and core but each version maps to a particular version of netstandard. So when I say I wouldn't expect that to work it is because .NET 4.6 maps to netstandard1.3 so I would expect the tooling to only allow you to reference up to that netstandard version. |
Adding this reference works for me direct inside csproj file with .NET 4.7.1. And for MVC5 projects with .NET 4.7.1 the build process dont copy this file to the output I have to copy manually and that fix the problem. |
@techaimail This method worked for me! |
@techaimail it worked for me too, thanks. |
Does this solution work for Azure too? When trying to deploy a 4.7 app that references a ns20 package to Azure, I get the following output:
|
Hi, I've got this same/similar problem. It compiles just fine, but when I call IRazorViewEngine.GetView, passing it the name of a cshtml file, I get a compilation exception with the following: The type 'Attribute' 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 and a number of similar complains about System.Void, Boolean etc. Anyone got any ideas? Séamus |
@joperezr .NET Framework 4.7.1 |
@shaulbehr I see that makes sense, the reason why you aren't seeing it on the bin folder is because netstandard.dll is inbox on 4.7.1. That means that at runtime you won't need to carry it with the app because it will just be loaded from the GAC. What specific error are you seeing? Also, is it at runtime or compile time? |
I have a dotnet Core web api project with targetFramwork .Net 4.7. (not 4.7.1)
The solution has some library projects that use .Net Standard 2.0. It was ok. Now I have that error at runtime when I execute this:
The libraries do other some jobs without any error, also this one is fine: So the problem exists only calling .Deserialize() Visual Studio Pro 15.5.4 on Windows x64 None of the workarounds in this tread worked for me. |
Is anyone here using automatic binding redirects when mixing in .net standard with .net full? If you're not, you should be. And you should be deploying all .config files (where the binding redirects are written to). Once I got automatic binding redirects configured all these gross issues went away. |
@alex-piccione Are you using the latest version of VS? do you have binding redirects turned on as @TechnikEmpire suggests? That combination should make your problem go away. |
Yes, I'm using the latest VS (15.5.4).
and this:
(#552) I also tried this: and this: I tried also to reference the I cannot switch from To be honest I haven't understood what "binding" means here... I tried to pass the XmlSerializer directly to the class in the .Net Standard library, the result is strange. The XmlSerializer instantiated in the library raise the error not in the .Deserialize() call as I say before but when I try to create it ( new XmlSerializer(typeof(MyData)) ). Give up. That's all. |
ASP.NET app targeting 4.7.1, solution is a mix of .NET FX and .NET Standard projects, including .NET Standard projects referencing .NET FX libraries. VS 15.5.6 with .NET Core SDK 2.1.4 installed. The only advice from this thread that helped to avoid
in an .cshtml was adding |
Since NETStandard.Library.NETFramework, and we should install the .NET Core 2.0 SDK, how do we do this from nuget CLI? |
@mallochine I'm not sure I understand your question, but if it is how to get this fix if you are building with the CLI directly (instead of using VS) then the answer is that the CLI does also contain a version of the support package (NETStandard.Library.NETFramework) inserted, and will use it to build. Whenever we upgrade the version of this package that we insert to VS, we also update the one on the CLI, which means that there will be a CLI that has this fix on it. |
I'm on Linux, so I'm using something like "nuget install -OutputDirectory". My compiler is mcs, which uses mono I suppose. That's weird, you're saying NETFramework should already be installed? All I see is
|
@valeriob could you fix the issue with Raven.Client.LightWeight reference? |
hi @iamisti |
Similar to the issue of @alex-piccione, only the usage of json.net (e.g. JsonConvert.SerializeObject()) raises this error: |
@alex-piccione @zipswich See this: https://github.com/dotnet/corefx/issues/18964
|
I encountered this issue in several projects when I copied them to a new solution. Invoking the Power Commands extension's |
I am having the same issue with visual studio build tools 15.6 and .NET Code SDK 2.0.2 installed. The host project is .NET 4.6.2 and the library being consumed is .NET Standard 2.0. When the library is downgraded to .NET Standard 1.1 it builds fine. |
I encountered this on a VSTS build, the solution builds fine in local visual studio 2017 15.7.5, however, I am getting the following on builds output: The type 'Object' 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'. The build is configured to use the latest visual studio version. |
need to add this to web.config, it solved this issue
|
thank you very much. |
I'm facing a similar problem: Does anyone have an idea of what is going on? |
Where in web.config do you a the XML code? |
Hi @mt89vein and everyone! Is there any way to tackle this in the system-level rather than in project level? e.g. without changing the web.config or .csproj |
I've added this section to my .csproj file and the issue is resolved.
|
We should not be changing the config file. I refrained from changing .config file in this case. I changed the Microsoft.NetFramework.CurrentVersion.targets file in C:\Program Files (x86)\MSBuild\14.0\Bin to include the lines below and my code started building fine
|
Hi,
i'm using vs 2017 15.3 Preview 2.
Create a netstandard2 project, a .net 4.6.1 project, add some reference to both, and reference netstandard2 library from .net 4.6.1 one.
Attached the solution with the repro.
Thanks
Netstandard2 referenced by net461.zip
The text was updated successfully, but these errors were encountered: