Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A reference to could not be added ´. An assembly must have a dll or exe extension in order to be referenced

Tags:

c#

.net-core

I have plain c# console application (.NET 4.6) where I want to reference a .NET Core Class Library:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Newtonsoft.Json": "9.0.1"
  },

  "frameworks": {
    "netstandard1.4": {
      "imports": "dnxcore50"
    }
  }
}

And I get the following exception:

enter image description here

like image 297
Legends Avatar asked Jul 13 '16 01:07

Legends


People also ask

Is defined in an assembly that is not referenced you must add a reference to?

The type 'System. Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.

What is not referenced in an assembly?

When you get this error, it means that code you are using makes a reference to a type that is in an assembly, but the assembly is not part of your project so it can't use it. Deleting Project. Rights. dll is the opposite of what you want.


1 Answers

Simple solution:

My .NET console application uses .NET 4.6 and should reference a Core Class Library using .NET Platform Standard 1.4.

Mapping the .NET Platform Standard to platforms says that .NET 4.6 is compatible with .NET Platform Standard 1.3.

Changing the project.json of the Core Class Library to (excerpt)

"frameworks": {
    "netstandard1.3": {
      "imports": "dnxcore50"
    }
  }

solved the problem.

Here is a compatibility table demonstrating the problem (.NET 4.6 is compatible with .NET Platform Standard <= 1.3): enter image description here

like image 52
Legends Avatar answered Sep 20 '22 20:09

Legends