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"
}
}
}
}
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"
}
}
Related
I am getting the following compilation error using .NET Core 1.0:
“The type or namespace name 'DataException' could not be found (are you missing a using directive or an assembly reference?)”, code: CS0246.
project.json
{
"name": "Dna.Net.Core",
"version": "1.0.0-*",
"dependencies": {
"Autofac": "4.1.0",
"NETStandard.Library": "1.6.0",
"System.Data.SqlClient": "4.1.0",
"System.Runtime": "4.1.0",
"System.Runtime.Serialization.Formatters": "4.0.0-rc3-24212-01",
"System.Runtime.Serialization.Primitives": "4.1.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
corefx: System.Data.SqlClient
48 <Compile Include="System\Data\DataException.cs" />
IDataExceptionMessageHandler.cs
using Dna.Net.Core.Common;
using System.Data;
namespace Dna.Net.Core.Exceptions
{
public partial interface IDataExceptionMessageHandler
{
CustomMessage Execute(DataException exception);
CustomMessage ParseMessage(DataException exception, CustomMessage customMessage);
void LogException(string message);
}
}
Does .NET Core 1.0 support System\Data\DataException.cs?
The file is there but it doesn't have DataException class -https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/System/Data/DataException.cs
It doesnt support.
I have a project that compiles that I want to test using xUnit. However although the project lets me add the references and builds, as soon as I add a using statement to the test class I get the red squiggly lines and the error "type or namespace could not be found."
Even though the xproj of the project I want to test has been added to references, and the namespaces do exist. It has to be something I have done, but I can't see what. Using earlier versions of .net, I have added references to test projects hundreds of times without an issue.
So what is different in the way .NET works, and why does it not recognize my namespaces in my referenced assemblies?
Update: I have removed xUnit and got MSTest working, but I have the same issue. So this may be a feature of the way I have dotnetcore set up, and the references in my json files more than anything else.
This structure works for me in .NET Core 1.0:
global.json
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
src/MyLibrary/project.json
{
"dependencies": { },
"frameworks": {
"netstandard1.3": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
}
},
"version": "1.0.0"
}
test/MyLibrary.Test/project.json
{
"dependencies": {
"dotnet-test-xunit": "2.2.0-preview2-build1029",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"MyLibrary": {
"target": "project",
"version": "1.0.0"
},
"xunit": "2.1.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dnxcore50",
"portable-net45+win8"
]
}
},
"testRunner": "xunit",
"version": "1.0.0"
}
Using this directory and project structure, both the Visual Studio Test Explorer and dotnet test work and can run xUnit tests.
I need to reference a dll which calls an old web service (not svc, but the older one). I'm not quite sure how to go about doing that. I'm using the RC1 version. I could call the web service directly but I'm not sure how to do that either in MVC6.
If I add the dll directly I get the error:
The name '*' does not exist in the current context
FieldOps.DNX Core 5.0
Here's what part of my project.json looks like where the library added is called "MyLibrary":
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Runtime.Serialization": "4.0.0.0",
"System.ServiceModel": "4.0.0.0"
},
"dependencies": { "MyLibrary": "2.2.0" }
},
"dnxcore50": {
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Http": "4.0.11-beta-23516",
"System.ServiceModel.NetTcp": "4.1.0-beta-23516",
"System.ServiceModel.Duplex": "4.0.1-beta-23516",
"System.ServiceModel.Security": "4.0.1-beta-23516",
"System.Net.NameResolution": "4.0.0-beta-23516",
"System.Net.Security": "4.0.0-beta-23516",
"System.Security.Principal.Windows": "4.0.0-beta-23516",
"System.Diagnostics.Tools": "4.0.1-beta-23516"
}
}
},
Why in the project.json is there a “dependencies” element outside of any of the target “frameworks”? When do dependencies go there versus under \frameworks\net451\frameworkAssemblies or \frameworks\dnxcore50\dependencies
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System": "4.0.0.0",
}
},
"dnxcore50": {
**** "dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
}
}
},
****"dependencies": {
"System.Diagnostics.Tools": "4.0.1-beta-23516",
"System.Threading.Timer": "4.0.1-beta-23516"
}
Each framework (net451/dnxcore50) can have different dependencies. Let's say that you are porting a legacy app that depends on some 3rd party NuGet library that's only available for desktop CLR. In that case you can add it to the dependencies in net451 and then mock it for dnxcore50. That way, you'll not get compilation errors.
frameworkAssemblies vs dependencies = GAC vs NuGet packages. frameworkAssemblies is only available for desktop CLR and it is used to reference GAC assmblies.
The documentation for using project.json for ASP.NET 5 applications includes a sample project.json file (abbreviated version below).
What is the difference between frameworkAssemblies and dependencies?
And why does dnx451 use one and dnxcore50 use the other?
{
"version": "0.1-alpha-*",
...
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
...
}
},
"dnxcore50": {
"dependencies": {
...
}
}
}
frameworkAssemblies refers to assemblies present in GAC (global assembly cache).
Consider the following example:
I want to use ADO.NET apis(SqlConnection, SqlCommand) to work with a SQL Server database. I know that these apis are part of System.Data.dll and so want to reference it. Now when the full version of .NET Framework is installed, it installs some assemblies in the GAC (which has this System.Data.dll too) and hence you see a reference to frameworkassemblies in the below example. Coming to CoreClr, I need to find out in which package these types exist. For this you could use the website called PackageSearch(built by an ASP.NET team member) where you can search for a type and find the package name. Based on this you will find System.Data.SqlClient to be the package. Since this package is built for CoreClr, it is part of dependencies section within the dnxcore50 section.
{
"version": "1.0.0-*",
"description": "Test App",
"dependencies": {
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": {
"dependencies": {
"System.Data.SqlClient": "4.0.0-beta-*"
}
}
}
}
Now let's say you want to even add support for json serialization and deserialization in your app and want to reference Json.Net nuget package. Json.Net nuget package supports both the desktop and core clr and hence you would put it in the dependencies section common to both frameworks.
{
"version": "1.0.0-*",
"description": "Test App",
"dependencies": {
"Newtonsoft.Json": "6.0.6"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0"
}
},
"dnxcore50": {
"dependencies": {
"System.Data.SqlClient": "4.0.0-beta-*"
}
}
}
}