dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.45k stars 10.03k forks source link

Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache. #1157

Closed RehanSaeed closed 6 years ago

RehanSaeed commented 8 years ago

Not sure where to post this...

I have the following project.json using several frameworks from .NET 4, all the way up to 4.6.1 and also Serilog is added as a global dependency, while all the frameworks except .NET 4 also have Serilog.Sinks.EventLog as an additional dependency. If I remove the System.Runtime references I get 37 of these errors:

Severity Code Description Project File Line Suppression State Error CS0012 The type 'Exception' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Bridge.Logging..NET Framework 4.5, Bridge.Logging..NET Framework 4.5.1, Bridge.Logging..NET Framework 4.5.2, Bridge.Logging..NET Framework 4.6 C:\Bitbucket\Bridge.Logging\Source\Bridge.Logging\LogEventEnrichers\ExceptionEnricher.cs 52 Active

If I publish my NuGet package and then try to install it, I get the following error:

Failed to add reference to 'System.Runtime'. Please make sure that it is in the Global Assembly Cache.

Why am I being forced to add System.Runtime and what does this achieve?

My project.json

{
  ...

  "dependencies": {
    "Serilog": "1.5.14"
  },

  "frameworks": {
    "net40": {
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    },
    "net45": {
      "dependencies": {
        "Serilog.Sinks.EventLog": "1.5.11"
      },
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    },
    "net451": {
      "dependencies": {
        "Serilog.Sinks.EventLog": "1.5.11"
      },
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    },
    "net452": {
      "dependencies": {
        "Serilog.Sinks.EventLog": "1.5.11"
      },
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    },
    "net46": {
      "dependencies": {
        "Serilog.Sinks.EventLog": "1.5.11"
      },
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    },
    "net461": {
      "dependencies": {
        "Serilog.Sinks.EventLog": "1.5.11"
      },
      "frameworkAssemblies": {
        "System": "",
        "System.Core": "",
        "System.Data": "",
        "System.Runtime": ""
      }
    }
  }
}
RehanSaeed commented 8 years ago

The solution was to make System.Runtime a build time dependency like so:

// Old
"System.Runtime": ""

// New
"System.Runtime": {
  "type": "build",
  "version": ""
}

I'm not entirely sure what this means so any helpful comments would be much appreciated.

gmarz commented 8 years ago

We've also just hit this, see https://github.com/elastic/elasticsearch-net/issues/1774

Setting "type": "build" as @RehanSaeed mentioned above does seem to do the trick, but I have no idea what the implications are. Is there any documentation on this?

RichiCoder1 commented 8 years ago

Also just ran intom this. Same concern as gmarz.

aspnet-hello commented 6 years ago

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.