Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

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

Closed
valeriob opened this issue Jun 12, 2017 · 68 comments

Comments

@valeriob
Copy link

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

@joperezr
Copy link
Member

I believe you are missing a reference to NETStandard.Library.NETFramework package. You can find it here

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.

@valeriob
Copy link
Author

Hi,
i added the reference to NETStandard.Library.NETFramework in the Net461 project but still does not work, check out my attachment.

Netstandard2 referenced by net461.zip

@dasMulli
Copy link

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 NETStandard.Library.NETFramework to the executing project you are using the library from or add this to the csproj file of the .net library:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

@valeriob
Copy link
Author

valeriob commented Jun 13, 2017

Hi @dasMulli,
i added

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> 

to the net461 project but nothing changes.
I thought that interoperability between netFramework vs netstandard was a priority on vs 2017 15.3, how can be possible i encounter this problem ?

Thanks again

@weshaggard
Copy link
Member

I thought that interoperability between netFramework vs netstandard was a priority on vs 2017 15.3, how can be possible i encounter this problem ?

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.

1>D:\git\tests\samples\netfx_ns\Net461\Class1.cs(15,25,15,44): error CS0012: The type 'IDocumentStore' is defined in an assembly that is not referenced. You must add a reference to assembly 'Raven.Client.Lightweight, Version=3.5.3.0, Culture=neutral, PublicKeyToken=null'.

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.

@valeriob
Copy link
Author

Hi @weshaggard
i was using the wrong package ! I added the reference to NETStandard.Library instead of NETStandard.Library.NETFramework i did not know there where many of them.
Then i'll ask the library author to fix that other problem.
Thanks again

StephenCleary added a commit to StephenClearyApps/DotNetApis that referenced this issue Aug 22, 2017
@gerektoolhy
Copy link

FYI, Not sure if this is related, but perhaps some will find this useful.

net461 framework with aspnetcore. Was getting similar exceptions:

error CS0518: Predefined type 'System.Object' is not defined or imported
error CS0518: Predefined type 'System.String' is not defined or imported
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'.
error CS0518: Predefined type 'System.Void' is not defined or imported
<...>\Views\Home\Index.cshtml(2,5): error CS0012: The type 'ViewDataDictionary<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

This was due to a wrong SDK. Updated to <Project Sdk="Microsoft.NET.Sdk.Web"> from <Project Sdk="Microsoft.NET.Sdk"> and issue is gone. Hope someone will find this useful, as it took me hours to drill down to this.

@ManfredLange
Copy link

ManfredLange commented Sep 10, 2017

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?

@daveh101
Copy link

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?

@weshaggard
Copy link
Member

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?

@ManfredLange What version of msbuild are you using from the command line? Be sure to be running from a VS 2017 dev command prompt.

I have just installed the .NET Standard 2.0.2 SDK

@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.

@daveh101
Copy link

@weshaggard
I have upgraded my Visual Studio to the latest preview version as suggested in this post about .NET Standard 2.0 & UWP

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:

error : Project ‘.csproj’ targets ‘.NETStandard,Version=v2.0’. It cannot be referenced by a project that targets ‘UAP,Version=v10.0.16267’

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
Copy link
Member

@daveh101 I see I'm not even sure which SDK that is but I believe it is the .NET Core SDK. At any rate while this is a similar error it is a unique issue for UWP can you please file a new issue for this with the information.

cc @joperezr @nattress

@ManfredLange
Copy link

ManfredLange commented Sep 11, 2017

@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.

@weshaggard
Copy link
Member

@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.

@zidad
Copy link

zidad commented Sep 23, 2017

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.
dotnet --version: 2.0.0

When I build a (very simple) project:


C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: The "ResolvePackageDependencies" task failed unexpectedly.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Message
\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<NuGet.Packaging.Core.PackageDependency> NuG
t.ProjectModel.LockFileTargetLibrary.get_Dependencies()'.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageDependencies(LockFileTargetLibrary package, String targetNa
e, Dictionary`2 resolvedPackageVersions, HashSet`1 transitiveProjectRefs)\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)\r [C:\Projects\P
card\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                 
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()\r [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany
MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                        
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany
MyProduct.Messages.csproj]                                                                                                                                                                                                                                              
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\Projects\MyCompany\picar
.citrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                            
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: The "ResolvePackageDependencies" task failed unexpectedly.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Message
\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<NuGet.Packaging.Core.PackageDependency> NuG
t.ProjectModel.LockFileTargetLibrary.get_Dependencies()'.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageDependencies(LockFileTargetLibrary package, String targetNa
e, Dictionary`2 resolvedPackageVersions, HashSet`1 transitiveProjectRefs)\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)\r [C:\Projects\P
card\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                 
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()\r [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany
MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                        
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany
MyProduct.Messages.csproj]                                                                                                                                                                                                                                              
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\Projects\MyCompany\picar
.citrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                            
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\Projects\MyCompany\MyProduct\Pica
d.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                         
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(15,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(16,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(17,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj] 
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,99): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyCompany.
itrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                              
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(10,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(11,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(12,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(13,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(14,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(15,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(16,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(17,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   

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.

@TechnikEmpire
Copy link

@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.

@weshaggard
Copy link
Member

@weshaggard so I'm assuming mixing .net standard 2 with 4.6 is unsupported as well?

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.

@TheCodechimp
Copy link

@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.

@weshaggard
Copy link
Member

@weshaggard Are you thinking of .NET core?

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.

@techaimail
Copy link

Adding this reference works for me direct inside csproj file with .NET 4.7.1.
<Reference Include="netstandard" />

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.
Microsoft please stop your continuous deliver if that is a fuc..k problem deliver, thanks for your advance but not thanks for this fails.

@stil
Copy link

stil commented Nov 13, 2017

@techaimail This method worked for me!

@borislavnnikolov
Copy link

@techaimail it worked for me too, thanks.

@mattglet
Copy link

mattglet commented Nov 15, 2017

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:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
All packages listed in packages.config are already installed.
  Core -> D:\home\site\repository\Core\bin\Release\Core.dll
Things\Thing.cs(18,41): 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'. [D:\home\site\repository\Models\Models.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\Website\Website.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d52be78b3540cb";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\.\\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\67.61109.3117\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"

@seamus-hoban
Copy link

Hi,

I've got this same/similar problem.
I'm running Studio 2017 (15.4.4 ). I created a .NET Core 2.0 command line project, adding Microsoft.AspNetCore and Microsoft.AspNetCore.Mvc, both version 2.0.1 to play around with using the Razor view engine to generate HTML strings rather than views.

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.
I've tried the csproj change listed above without success.

Anyone got any ideas?

Séamus

@shaulbehr
Copy link

@joperezr .NET Framework 4.7.1

@joperezr
Copy link
Member

@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?

@alex-piccione-spin
Copy link

I have a dotnet Core web api project with targetFramwork .Net 4.7. (not 4.7.1)

<Project Sdk="Microsoft.NET.Sdk.Web">
	<PropertyGroup>
		<!--<TargetFramework>netcoreapp2.0</TargetFramework>-->
		<TargetFramework>net47</TargetFramework>
		<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

The solution has some library projects that use .Net Standard 2.0.
It is ok.

It was ok.
Until I tried to use XmlSeriazer from Syste.Xml.Serialization.

Now I have that error at runtime when I execute this:

var myData = (MyData)new XmlSerializer(typeof(MyData))
                    .Deserialize([something that is an XElement].CreateReader());

The libraries do other some jobs without any error, also this one is fine:
var tempString = [something that is an XElement].ToString();
XDocument doc = XDocument.Parse(tempString);

So the problem exists only calling .Deserialize()

Visual Studio Pro 15.5.4 on Windows x64
Everything updated at last version.
Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

None of the workarounds in this tread worked for me.
Any suggestion ?

@TechnikEmpire
Copy link

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.

@joperezr
Copy link
Member

@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.

@alex-piccione-spin
Copy link

Yes, I'm using the latest VS (15.5.4).
I tried to use:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

and this:

    <PropertyGroup>
        <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>
    </PropertyGroup>

(#552)

I also tried this:
<PackageReference Include="NETStandard.Library" Version="2.0.1" />
that is exactly the same package referenced by the Library projects (.Net Standard)

and this:
<Reference Include="netstandard" />

I tried also to reference the
NETStandard.Library.NETFramework v2.0.0-preview2-....

I cannot switch from
Project Sdk="Microsoft.NET.Sdk.Web" to Project Sdk="Microsoft.NET.Sdk" because it is a web project.

To be honest I haven't understood what "binding" means here...
and the error is raised at runtime when I debug the code (not after the deploy).

I tried to pass the XmlSerializer directly to the class in the .Net Standard library, the result is strange.
It does not raise an error but it return a null object.
(The classes that map the XML is generated by xsd.exe).

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.
Using XDocument and XLinq works without any problems so I'm parsing the XML myself and I deleted all the code for this experiments. I cannot test it anymore.

That's all.

@Leon99
Copy link

Leon99 commented Feb 12, 2018

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

The type 'Decimal' 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'

in an .cshtml was adding
<Reference Include="netstandard"> <Private>True</Private> </Reference>
to the web app project. MSBuild works too.

@mallochine
Copy link

Since NETStandard.Library.NETFramework, and we should install the .NET Core 2.0 SDK, how do we do this from nuget CLI?

@joperezr
Copy link
Member

joperezr commented Mar 9, 2018

@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.

@mallochine
Copy link

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

[nutanix@alexand-guo v4.7.1]$ find
.
./RedistList
./RedistList/FrameworkList.xml

@iamisti
Copy link

iamisti commented Apr 9, 2018

@valeriob could you fix the issue with Raven.Client.LightWeight reference?
I have the same issue and I can't solve it

@valeriob
Copy link
Author

hi @iamisti
i was able to solve the problem like i said in my comment before closing.
I've never thought about it anymore, i think tooling improved a lot since then

@zipswich
Copy link

zipswich commented Jun 30, 2018

Similar to the issue of @alex-piccione, only the usage of json.net (e.g. JsonConvert.SerializeObject()) raises this error:
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'. ClassLibraryUno(uap10.0.16299)

@mayerwin
Copy link

mayerwin commented Jul 6, 2018

@alex-piccione @zipswich See this: https://github.com/dotnet/corefx/issues/18964
What solved this runtime error for me was to edit the .NET Standard 2.0 library .csproj file and add the following:

<PropertyGroup>
    <TargetFrameworks>netstandard2.0;net471</TargetFrameworks>
</PropertyGroup>

@CalvinDale
Copy link

CalvinDale commented Jul 6, 2018

I encountered this issue in several projects when I copied them to a new solution. Invoking the Power Commands extension's Edit Project File for just one of the projects and then Reload Project and finally Rebuild Solution resolved the issue in all of the projects.

@glenthomas
Copy link

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 have tried all suggested fixes. The NETStandard.Library.NETFramework package can resolve it, but nothing else works.

@C-M-Ryan
Copy link

C-M-Ryan commented Jul 18, 2018

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.

@zipswich
Copy link

@mayerwin Thanks for the tip. I solved the problem in a similar way - editing a target in the .csproj file. I forgot to take notes. My case is related to a Uno class library.

@mt89vein
Copy link

mt89vein commented Nov 6, 2018

need to add this to web.config, it solved this issue

<compilation debug="true" targetFramework="4.7.2">
     <assemblies>
       <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
     </assemblies>
   </compilation>

@hhq365
Copy link

hhq365 commented Jul 17, 2019

need to add this to web.config, it solved this issue

<compilation debug="true" targetFramework="4.7.2">
     <assemblies>
       <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
     </assemblies>
   </compilation>

thank you very much.

@diegostamigni
Copy link

I'm facing a similar problem:

xamarin/xamarin-macios#6886

Does anyone have an idea of what is going on?

@GASitton
Copy link

Where in web.config do you a the XML code?
G_S

@amoraitis
Copy link

amoraitis commented Jun 24, 2020

need to add this to web.config, it solved this issue

<compilation debug="true" targetFramework="4.7.2">
     <assemblies>
       <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
     </assemblies>
   </compilation>

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

@joshuanoelsantos
Copy link

Where in web.config do you a the XML code?
G_S

Just in case someone else is wondering aside from him.

image

@bharathbkt
Copy link

bharathbkt commented Nov 1, 2021

@dasMulli

I've added this section to my .csproj file and the issue is resolved.

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

@SmithaKalluz
Copy link

SmithaKalluz commented Sep 1, 2022

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

<ItemGroup> <Reference Include="netstandard" /> </ItemGroup>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests