Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 · 61 comments

Comments

Projects
None yet
@valeriob
Copy link

commented Jun 12, 2017

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

This comment has been minimized.

Copy link
Member

commented Jun 12, 2017

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

This comment has been minimized.

Copy link
Author

commented Jun 13, 2017

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

This comment has been minimized.

Copy link
Contributor

commented Jun 13, 2017

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented Jun 13, 2017

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

This comment has been minimized.

Copy link
Author

commented Jun 15, 2017

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

@valeriob valeriob closed this Jun 15, 2017

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

@dariusdamalakas

This comment has been minimized.

Copy link

commented Aug 30, 2017

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Sep 11, 2017

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

This comment has been minimized.

Copy link
Member

commented Sep 11, 2017

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

This comment has been minimized.

Copy link

commented Sep 11, 2017

@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

This comment has been minimized.

Copy link
Member

commented Sep 11, 2017

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

commented Sep 11, 2017

@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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Oct 13, 2017

@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

This comment has been minimized.

Copy link
Member

commented Oct 13, 2017

@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

This comment has been minimized.

Copy link

commented Oct 23, 2017

@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

This comment has been minimized.

Copy link
Member

commented Oct 24, 2017

@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

This comment has been minimized.

Copy link

commented Nov 11, 2017

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

This comment has been minimized.

Copy link

commented Nov 13, 2017

@techaimail This method worked for me!

@Sesi0

This comment has been minimized.

Copy link

commented Nov 14, 2017

@techaimail it worked for me too, thanks.

@mattglet

This comment has been minimized.

Copy link

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"
@joperezr

This comment has been minimized.

Copy link
Member

commented Nov 15, 2017

@seamus-hoban I created issue aspnet/AspNetCore#2278 on the aspnet repo so that we can fork the discussion of this issue there. It is possible that what you want to do can be accomplished with a console app, so I'll ask you to please go to that issue and add more info to help the aspnet core guys determine whether your scenario should work with a console app or not.

@mattglet

This comment has been minimized.

Copy link

commented Nov 17, 2017

@joperezr were you able to reproduce?

@joperezr

This comment has been minimized.

Copy link
Member

commented Nov 17, 2017

@mattglet not yet but we have received several similar reports, so we are looking into it now.

@mattglet

This comment has been minimized.

Copy link

commented Nov 19, 2017

I added a manual reference to netstandard.dll and added it to the solution - it's a successful temporary workaround until the (what I presume to be an) Azure bug is fixed.

@nikitozz

This comment has been minimized.

Copy link

commented Nov 20, 2017

@ManfredLange,
Just wondering, were you able to find a solution? I'm experiencing the same issue: my build works from VS but not from MSBuild.

Thank you.

@joperezr

This comment has been minimized.

Copy link
Member

commented Nov 21, 2017

Do you have more than one msbuild installed? it might be that you are using the old one when invoking from command prompt. If so, I would try manually adding a reference to netstandard to your project so that it works with older VS and msbuild.

@ManfredLange

This comment has been minimized.

Copy link

commented Nov 22, 2017

@nikitozz What we are doing at the moment is this: We parse solution and project file for dependencies, then create our own sequence of building each project. We use batches where multiple things can be build in parallel. We no longer rely on msbuild or dotnet to figure it out for our solution (50+ projects, mix of old/new csproj format, netstandard2.0, netcoreapp2.0, net461).

Then we build all except one project using dotnet build <projectfile> with appropriate parameters e.g. macros required by post-build events. One project is built using msbuild located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin this is the latest version included in VS 2017 Professional Version 15.4.4. The "File version" of msbuild.exe as per file properties is 15.4.5.50001.

One additional caveat: we also need to always ensure that we can deploy as Azure App Service. This means it needs to pass a test there as well as we have no influence over what version of msbuild is installed there.

This approach has been working for us for a few weeks now. Ideally we would love to just throw a solution file at either msbuild or dotnet build but so far we ran into problems each time we tried because of the mix of projects in our solution.

Good luck!

@shaulbehr

This comment has been minimized.

Copy link

commented Nov 23, 2017

I was also getting this error, so I made a reference to NetStandard.Library 2.0.1 using NuGet. Deployed, and still got the same error. Then I saw that netstandard.dll isn't being deployed to the bin folder. And, in fact, NetStandard.dll doesn't show up in the project references in the Solution Explorer.
Is that a bug in the NuGet package? Is there some trick I'm missing that is meant to add the DLL reference to the project?

@joperezr

This comment has been minimized.

Copy link
Member

commented Nov 27, 2017

@shaulbehr what TFM is your project targeting?

@shaulbehr

This comment has been minimized.

Copy link

commented Nov 28, 2017

@joperezr .NET Framework 4.7.1

@joperezr

This comment has been minimized.

Copy link
Member

commented Nov 28, 2017

@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

This comment has been minimized.

Copy link

commented Jan 22, 2018

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

This comment has been minimized.

Copy link

commented Jan 22, 2018

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

This comment has been minimized.

Copy link
Member

commented Jan 23, 2018

@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

This comment has been minimized.

Copy link

commented Jan 24, 2018

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Mar 9, 2018

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

@joperezr

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

commented Mar 9, 2018

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

commented Apr 10, 2018

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jul 6, 2018

@alex-piccione @zipswich See this: dotnet/corefx#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

This comment has been minimized.

Copy link

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.

@MrGlenThomas

This comment has been minimized.

Copy link

commented Jul 12, 2018

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.

@Cryan24

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

commented Jul 18, 2018

@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

This comment has been minimized.

Copy link

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.