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

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

Closed
daveh101 opened this issue Sep 21, 2017 · 11 comments

Comments

@daveh101
Copy link

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?

@daveh101
Copy link
Author

daveh101 commented Sep 21, 2017

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.

@weshaggard
Copy link
Member

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 dotnet/msbuild#2567 where we aren't correctly detecting netstandard.

cc @dsplaisted @AlexGhiondea

@dsplaisted
Copy link
Member

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

<_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>

@ghost
Copy link

ghost commented Oct 18, 2017

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

@AdamDotNet
Copy link

AdamDotNet commented Nov 3, 2017

@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.
  1. Add new Project -> netstandard2.0 class library
  2. Add a static method Foo returns string "Hello World" to Class1 in the netstandard2.0 library.
  3. Add project reference of netstandard2.0 library to Asp.Net project.
  4. 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.

@alfeg
Copy link

alfeg commented Dec 8, 2017

@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

@alfeg
Copy link

alfeg commented Dec 8, 2017

@AdamDotNet - there is another workaround that a bit help us - #542 (comment)

@AdamDotNet
Copy link

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

@npakudin
Copy link

npakudin commented Apr 3, 2018

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.

@AlexGhiondea
Copy link

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

@wtgodbe
Copy link
Member

wtgodbe commented May 30, 2019

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

@wtgodbe wtgodbe closed this as completed May 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants