6

I'm trying to split my .NET Core project into separate concerns using Class Libraries. I want one (or many) Class libraries and one host project. Class libraries will define the MVC Controllers and the business logic while the host project will be in charge of providing a working host. Unfortunately, the project reference refuses to work.

Let me give you the steps I took to arrive at this issue.

  1. Create an empty solution in Visual Studio 2015 Update 3
  2. Create a project of type Class Library (.NET Core) named ClassLibrary1
  3. Go to the project.json and modify it to make it look like the one below.
  4. Create a project of type Console Application (not .NET Core) named ConsoleApplication1
  5. Right-click in References under ConsoleApplication1 and add ClassLibrary1 as a Project reference.
  6. Refer to a type that exists in ClassLibrary1.
  7. Build the solution.

This will lead to a Build failure in the ConsoleApplication1 project with the code error CS0246: The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?). If instead of adding the reference as a Project reference I go and browse to the bin folder and refer to the dll directly, everything builds without an issue. However, this is not a solution since the Build target may change, so the path will change as well.

Code of the project.json:

{
  "version": "1.0.0-*",

  "dependencies": {
    
  },

  "frameworks": {
    "net452": {
    }
  }
}

Is this a Visual Studio bug, or am I doing something wrong? I tried using netstandard1.2, net452, but the result remains the same.

EDIT I created an issue in the .NET CLI Github repository. Here is the link: https://github.com/dotnet/cli/issues/3926.

4
  • did you make ClassLibrary1 target the netstandard1.2 in its project.json? Commented Jul 15, 2016 at 5:32
  • same issue with this stackoverflow.com/questions/38148128/… ? Commented Jul 15, 2016 at 8:53
  • @enzian Yes, I tried without success. Commented Jul 15, 2016 at 10:31
  • @kurakura88 Thanks, but I've looked into it and this is not a duplicate. I'm not trying to reference a full .NET assembly into a Core project, but rather a plain old assembly that compiles to 4.5.2 into a Console application. Commented Jul 15, 2016 at 10:33

1 Answer 1

0

I had a similar issue with Microsoft.NETCore 5.0.1 in a PCL. It didn't even find System.Object.

I tried downgrading to 5.0.0 and that solved it for me.

Sign up to request clarification or add additional context in comments.

5 Comments

What is your analysis of the underlying problem, and how is your suggestion a resolution for this problem?
I use the SAME library, and the current version on NuGet gives me tons of SIMILAR errors (XYZ could not be found). It is apparently broken. Downgrading solved it for me.
I have no idea what causes theses errors (they make no sense to me), just how I resolved them. Shouldn't I have shared that? I'm at a total loss what you expect from me. EDIT: Sure just delete what you wrote.
If you're sharing your experience (or: anecdotal data), it would be more appropriate to do this in a comment on the question. If you actually have an answer that works for all users experiencing this problem, with an explanation of the error and the resolution, then specifying it as an answer is valid.
Okay. Just for reference: What other explanation than "It's a bug" would you have expected? Me debugging the Microsoft library? Because my resolution is certainly present.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.