1

I just added a class library project to my new solution and am only given the option of the new class library type. I created my domain classes, which use EF data annotations from System.Component.DataAnnotations. The classes themselves have no errors but the project wont build. I get these errors.

Severity Code Description Project File Line Error CS0234 The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4 C:\Users\Thomas Donino\Documents\GitHubVisualStudio\TraderToolkit2016\TraderToolkit2016.DomainClasses\AppClasses\DailyClose.cs

I have the assembly referenced. Why am I getting these errors?

Here is my project.json file, DataAnnotations added automatically from VS right click.

{
 "version": "1.0.0-*",
 "description": "TraderToolkit2016.DomainClasses Class Library",
 "authors": [ "Thino" ],
 "tags": [ "" ],
 "projectUrl": "",
 "licenseUrl": "",

 "frameworks": {
   "net451": {
     "frameworkAssemblies": {
       "System.ComponentModel.DataAnnotations": "4.0.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"
     }
   }
 }
}
dinotom
  • 4,990
  • 16
  • 71
  • 139

1 Answers1

1

This mean that you are making your project compatible with 2 platforms. one is net451 and another is dotnet5.4.

"frameworks": {
   "net451": {
     "frameworkAssemblies": {
       "System.ComponentModel.DataAnnotations": "4.0.0.0"
     }
   },

This means that you have added reference of System.ComponentModel.DataAnnotations only to net451 target. and that's why you get following error:

are you missing an assembly reference?) TraderToolkit2016.DomainClasses..NET Platform 5.4 

Notice the 5.4 in the end of error message.

Now the solution is to either remove dotnet5.4 if you dont need it or add a reference of System.ComponentModel.DataAnnotations to dotnet5.4 to it as well. You can do that by simply installing this nuget package:

https://www.nuget.org/packages/System.ComponentModel.Annotations/4.0.11-beta-23516

Or simply modifying the file so that it looks like this:

"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"
       "System.ComponentModel.Annotations": "4.0.11-beta-23516"
     }
   }
Bilal Fazlani
  • 6,727
  • 9
  • 44
  • 90
  • the edit worked. Man they made this a difficult process and there is little documentation to explain the travails of getting this done properly – dinotom Dec 15 '15 at 18:34
  • tell me about it. I have spent hours and days to understand this shit. it cant get more complicated than this. – Bilal Fazlani Dec 15 '15 at 18:34
  • if I want to only target .net451 can I just remove the whole reference in project.json for that? and delete the ,Net Platform 5.4 under references? – dinotom Dec 15 '15 at 18:51
  • yeah, you can remove the "dotnet5.4" section completely then, – Bilal Fazlani Dec 15 '15 at 18:52