Standard: ASP.NET 4.7.1 - The type 'Enum' is defined in an assembly that is not referenced

Created on 21 Sep 2017  路  11Comments  路  Source: dotnet/standard

This is likely a very similar issue to #391 & #489.

There is a big chance here that I am being an absolute idiot!! But, we are looking at migrating all of our code across to using .NET Standard 2.0 instead of PCL's - this is part of our work with UWP (#489).

The issue here is now when looking at one of our websites, I get the follow issue (see image)
capture

CS0012: The type 'Enum' 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'.

There is an Enum that is in a .NET Standard 2.0 project that is being referenced this.Links[i].Type in the aspx file.

There is no problem with referencing this enum in the .cs file (or other items in the .NET Standard Projects).

What do I need to do to make this work on an ASPX file.

I have tried all the bits mentioned in the related issues, but none seem to help.

@weshaggard - I assume this might be one for you again?

netfx-compat

Most helpful comment

@daveh101 Can you try adding the following property to your .csproj and let us know if it works around the issue?

<_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>

All 11 comments

Are the problems here related to #481? - It doesn't mention 4.7.1, but the project is certainly working from packages.config

UPDATE
I have now followed everything in the above, including converting projects across to the VS 2017 format where possible.

But, still giving the same issues as above.

TO clarify, there are no issues with the .cs files, it is all with the .aspx files where they reference something that uses a .NET Standard 2.0 object of some kind.

You are correct that .NET 4.7.1 should contain all of .NET Standard 2.0 inbox and shouldn't even require a reference to NETStandard.Library package any longer.

I suspect you are hitting this issue https://github.com/Microsoft/msbuild/pull/2567 where we aren't correctly detecting netstandard.

cc @dsplaisted @AlexGhiondea

@daveh101 Can you try adding the following property to your .csproj and let us know if it works around the issue?

<_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>

@dsplaisted I ran into the same issue with a project targeting net471 and netstandard2.0 (it doesn't seem to occur with net471 only).
Setting this property for the net471 configuration fixed it for me. Thanks for the hint!

@daveh101 - That CSProj property does not fix my project, unfortunately.
1. File new Asp.Net Application (full framework) on .Net 4.7.1. Choose MVC application.
- This is classic csproj, problem observed whether using PackageReference or packages.config.
2. Add new Project -> netstandard2.0 class library
3. Add a static method Foo returns string "Hello World" to Class1 in the netstandard2.0 library.
4. Add project reference of netstandard2.0 library to Asp.Net project.
5. Edit CSProj for Asp.net Application, in the first <PropertyGroup> add <DependsOnSystemRuntime>true</DependsOnSystemRuntime> and/or <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>. Reload csproj.
5. In a Razor file, such as _Layout.cshtml, add @ClassLibrary1.Class1.Foo()
6. Observe red squiggle 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'.
7. Application does indeed yellow screen if you run it.

I've spent days moving my projects to netstandard2.0 and .Net Framework 4.7.1 where applicable. Frankly it was a painful process, pouring over GitHub to find all of the needed workarounds for the tooling and .Net Framework not being quite setup right for .Net 4.7.1 to be fully netstandard2.0 compatible. It's very demoralizing to see it not work in the end. I've tried both VS 15.4.2 and Preview VS 15.5.0 P2.

I see two options left:

  1. Maybe I did the workarounds wrong and we can get it working. I'd be perfectly happy to be wrong if it means I get up and running.
  2. I downgrade back to 4.6.2 like I was before the upgrade process and hope that binds correctly with netstandard2.0.

@AdamDotNet, we have stumbled upon same issue on recently released VS 15.5.0 with the same result. @dsplaisted can be easily reproduced with provided steps, here is a link to project https://github.com/alfeg/NETSTANDARD_504

@AdamDotNet - there is another workaround that a bit help us - https://github.com/dotnet/standard/issues/542#issuecomment-339328208

@alfeg - I tried the web.config trick in a sample app and it indeed works! Thank you.

Unfortunately, a while ago I decided on the net462 solution for my actual application, but this is good to know if I take another stab at moving forward to net471. Maybe it'll just work in net472?

I have the same error message in .NET Standard project.

I'm migrating project from .NET Framework and have multiple similar errors:

  1. For System.Diagnostics.EventLogEntryType
    The type 'Enum' 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'.

public static void WriteEntry(object Source, string Message, EventLogEntryType EntryType) // error in this line on EventLogEntryType
{
...
}

  1. For HttpContext.Request.Cookies.Count
    The type 'IEnumerable' 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'
    Again - error just in method parameter type, as in example above.

  2. For Microsoft.AspNetCore.Http.HttpContext
    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'.
    Again - error just in method parameter type, as in example above.

What happens if you explicitly add a reference to netstandard.dll?

Closing for lack of traction, @daveh101 please re-open if you're still having trouble.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

praeclarum picture praeclarum  路  5Comments

ghost picture ghost  路  4Comments

xiedongweo picture xiedongweo  路  4Comments

mpetrinidev picture mpetrinidev  路  3Comments

sam-wheat picture sam-wheat  路  5Comments