How to add reference in VS 2015/.NET 4.6?
Asked Answered
S

3

10

Has VS 2015 changed drastically on how references are added?

I am doing a MVC web project. I wanted to use System.Configuration.ConfigurationManager in my .NET 4.6 application. I went to the the References node and Add Reference... and added System.Configuration 1.0.0.0. Intellisense now was able to automatically provide the properties and methods for ConfigurationManager, eg ConfigurationManager.AppSettings.

However, when I tried to compile, it says

CS0234 The type or namespace name 'Configuration' does not exist in the namespace 'System' (are you missing an assembly reference?)

How are things done in the new .NET Framework?

When I hover my mouse over the using System.Configuration statement, there's a balloon text with yellow triangle and exclamation mark that says:

{} Namespace System.Configuration
  MyProject.DNX 4.5.1 - Available
  MyProject.DNX Core 5.0 - Not Available
You can use the navigation bar to switch context.

Whatever does this mean?

Steddman answered 17/12, 2015 at 1:38 Comment(1)
did you find what the hell that means???Wrangle
E
2

It means that you have defined System.Configuration in DNX 4.5.1 which means is not available for DNX Core 5.0.

The project.json file is telling to the compiler that DNX Core 5.0 will be the main target framework. So if the System.Configuration namespace is not available in DNX Core 5.0 then you gonna get an error.

To solve this you need to switch the order of the frameworks defined in project.json

From:

"frameworks": {
    "dnxcore50": {
      },
      "dnx451": {
      }
   }

To

 "frameworks": {
        "dnx451": {
          },
          "dnxcore50": {
          }
       }

Then you are telling to the compiler that your main target framework now is DNX 4.5.1 which is a more complete but dependent framework (.NET Framework 4.5.1 != .NET Core)

.NET Core is a very small subset of .NET Framework which is useful for running your applications in non-windows environments such as Linux and Mac.

If you are targeting Windows environments I strongly recommend to target DNX 4.5.1 or 4.6

Extended answered 27/6, 2016 at 18:27 Comment(0)
F
0

Sorry that I still cant put a comment with my current points.

I suggest the things that you should do :

  • Add reference which targeting your current framework (reference -> add reference -> Assemblies -> Framework -> System.Configuration)
  • Try to add System.Configuration 4.0.0.0 instead of 1.0.0.0
  • Check whether have you added 'using System.Configuration;' in your program or not

Im using System.Configuration 4.0.0.0 and its working fine in Visual Studio 2015

you could check more in here

Fricandeau answered 17/12, 2015 at 2:6 Comment(4)
There is only 4.0 System.configuration 4.0.0.0 and no System.Configuration 4.0.0.0.Steddman
Then, have you tried to use 4.0 System.configuration 4.0.0.0 instead? @OldGeezerFricandeau
Exact same error message. I have added more information to my original question, something about switching contexts. Perhaps that may give a clue.Steddman
Do you use dnxcore50 in your project? If no, then you can just comment it out, and it will solve the problem. @OldGeezerFricandeau
F
0

The message You can use the navigation bar to switch context. shows when you have projects that use files added as link (context menu of a project and then Add->Existing Item...->Add As Link).

Example: assume that you have a C# file called sample.cs in a project ProjectA and the same file is referenced as a link in ProjectB. Then you write in sample.cs some code that uses library called Library. You also have reference to this Library only in ProjectA. So the ProjectB should also have reference to that library. If not - then this message appears: You can use the navigation bar to switch context. Full example message:

{} Namespace Library
ProjectA 1.0.0 - Available
ProjectB 1.0.0 - Not Available
You can use the navigation bar to switch context.
Fredenburg answered 8/3, 2017 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.