Visual Studio 2012 How to debug "Unable to add reference to project x" error?

13,565

Solution 1

Trying to add the built dll has a reference gave a more explicit error message which has solved the problem for me, it said:

“A reference to ‘x’ could not be added. The project targets ‘.NetFramework’ while the file reference targets ‘.NetCore’. This is not a supported scenario”

The MonoGame Class Library is a Class Library (Windows Store apps) type! (The bit in parenthesis is important! Presumably the difference is the Windows Store apps type use .Net Core which is not the same as .Net Framework).

So to get it working your project must be a Class Library (Windows Store apps) which is available under the Windows Store option in Add New Project.

Solution 2

I suspect the problem is to do with the 'Target Framework' in project options.

I don't know how MonoGame works for Windows 8 but when you're developing for Android the target framework options are the different versions of Android [e.g. Android 2.2 (Froyo)]. When you create a regular class library you have choices between the different versions of the .NET framework or Mono [e.g. Mono / .NET 4.0].

Unfortunately, these frameworks are not compatible with each other. You can't add a project reference for Android to a .NET framework class library and visa-versa.

The solution is to use a Portable Class Library. They are specifically designed to deal with this issue. The downside is that you will only have access to the subset of assemblies provided in the lowest denominator you choose to target.

You might also want to consider code sharing between projects using linked files. It can make maintenance a little trickier but gives you a little more control over code that should compile in both target frameworks but doesn't fit into the portable class library. Here's a related question:

Project reference vs. file links in Mono multi-target projects

The key to all of this once you understand what's going on here is how you structure your solution. With a little care you can have nearly all your code shared across different platforms.

Solution 3

I might be because of both projects are using different Framework versions and change the Framework versions in both Projects of properties section then your problem might solve.

Solution 4

Same question I guess here: Visual Studio 11 metro apps unable to add reference?

The answer was:

What are you adding a reference to? Metro style apps can only add references to other Metro style class libraries or portable class libraries

Share:
13,565
markmnl
Author by

markmnl

My blog: http://athreadwithnoname.com/

Updated on June 05, 2022

Comments

  • markmnl
    markmnl almost 2 years

    In Visual Studio 2012 in a blank new Class Library I am trying to add reference to an existing project in the solution, also a Class Library, MonoGame.Framework.Windows8 (https://github.com/mono/MonoGame), but get the error:

    Unable to add reference to Project MonoGame.Framework.Windows8

    I have built the existing library, MonoGame, successfully and made it a dependency of the new one. What could be the problem?

    (It's extremely annoying the error message does not give a reason!)

  • NibblyPig
    NibblyPig over 11 years
    Been tearing my hair out over this. It's quite sneakily hidden! Thanks!