1

Not seeing this exact situation in the question search.

I added a net framework 4.7.2 library to a web page solution with 3 projects in it that were all 4.7.1. It worked fine until I actually tried to reference an object in the 4.7.2 library.

I figured out the problem, and set every project to 4.7.2.

It builds perfectly fine. But when I run it, I get this error:

Compiler Error Message: CS0012: The type 'System.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'.


Line 82:         <img src="/images/0421-NV.png" class="img-responsive" />
Line 83:         <div class="textDiv">
Line 84:             @Html.Snippet("mysnippetname")  <<-- this line is highlighted
Line 85:         </div>
Line 86:     </div>

I'm stumped as to why it's demanding a netstandard reference when I don't have any netstandard projects in the solution. It also didn't complain about it before when I was using 4.7.1. I didn't add any new code between when it was using 4.7.1 and compiled and ran.

Any ideas?

Edit: I changed everything to 4.7.1 to test, and it still gives me the same error.

Edit2: I did try adding the following to the web.config but I still get the same error:

   <system.web>
    <httpRuntime targetFramework="4.6.1" maxRequestLength="32768"/>
      <compilation debug="true" targetFramework="4.5">
        <assemblies>
          <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </assemblies>
    </compilation>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Does this answer your question? [The type 'System.Object' is defined in an assembly that is not referenced](https://stackoverflow.com/questions/24396711/the-type-system-object-is-defined-in-an-assembly-that-is-not-referenced) – Orace Apr 30 '21 at 16:54
  • 1
    Just search "Compiler Error Message: CS0012: The type 'System.Object' is defined in an assembly that is not referenced." in ggl. https://stackoverflow.com/questions/24396711 https://stackoverflow.com/a/31241441/361177 ... – Orace Apr 30 '21 at 16:55
  • @Orace thanks unfortunately that doesn't help. I did find that before and tried it but I still get the same error. –  Apr 30 '21 at 17:04
  • I assume you already restarted Visual Studio... Have you tried right clicking the solution -> Restore NuGet Packages? Perhaps something else to check is if the .net framework 4.7.2 sdk is actually installed: https://dotnet.microsoft.com/download/visual-studio-sdks – Pieterjan Apr 30 '21 at 17:11
  • 1
    @Pieterjan restore nuget packages didn't help but it was a good thought. I'm pretty sure 4.7.2 is installed ok as I've been using it on other projects. I also reset the projects back to 4.7.1 to test but it gives me the same error. –  Apr 30 '21 at 17:59

1 Answers1

1

Aggh. Found the problem. Actually 2. The main project hadn't included the nuget package for the new library (which is idiotic on my part) and one of the existing projects had an old nuget package. Wasn't even using it as far as I can tell. I removed those and it works now.

Thanks for the suggestions everyone.