2

I am poking around ASP.Net MVC 5/ASP.Net Core and am getting errors when trying to build the project.

The error is simple enough on its own:

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

But...it does. The class name in the C# file is correctly 'coloured' and if I hover over it, Visual Studio understands what it is (class Entity in picture below).

My main project is a web app, but this problem is occurring in a sibling 'Class Library (package)' project. The reference was added by nuget.

Visual Studio showing hover help for class from referenced DLL

Any ideas what I might have done wrong or where I might look to try to debug?

The project.json looks like this:

{
  "version": "1.0.0-*",
  "description": "My Proj Name",
  "authors": [ "Robert" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "frameworks": {
    "net451": {
        "dependencies": {
            "Microsoft.Crm.Sdk.Proxy": "1.0.0-*",
            "Microsoft.CrmSdk.CoreAssemblies": "8.1.0"
            "Microsoft.Xrm.Client": "1.0.0-*"
        }
    },
    "dotnet5.4": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Runtime": "4.0.21-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}
David Pine
  • 23,787
  • 10
  • 79
  • 107
glosrob
  • 6,631
  • 4
  • 43
  • 73
  • 1
    show your project.json file – Joe Audette May 13 '16 at 14:13
  • I would do a clean and rebuild just to be sure something funky isn't going on with your references. Also make sure you are targeting the correct version of .NET framework, as this error can crop up if a properly referenced assembly is not part of the target framework. Entity Framework should require 3.5 or later I believe – Marshall Tigerus May 13 '16 at 14:19
  • Clean rebuilt, VS closed and reopened, same error unfortunately. – glosrob May 13 '16 at 14:38
  • Did you set the Properties of this Reference to "Compile" or even "Embed Interop Types = True" in the Solution Explorer? Are XRM also in the Solution References? Are you IMPORT/USING that in the header of the behind code? – David BS May 13 '16 at 14:42
  • Can you share the full error message? From which of the two frameworks does it come from? – Victor Hurdugaci May 13 '16 at 16:58

1 Answers1

1

You are referencing NuGet Package that has only "full" framework implementation while you are targeting both net451 and dotnet5. Tooltip for the Entity class (asterisk sign) should give you an idea about the error.

You have two options

  1. Remove dotnet5 from target frameworks - This means your application will work only on Windows and with framework 451
  2. Use conditional compilation to separate implementation for two frameworks.

e.g.

#if DNX451
        // utilize resource only available with .NET Framework
#endif
Enes
  • 1,115
  • 7
  • 12