I have one folder. In that I have three cs files.
Demo.cs
using System;
namespace Demo
{
public class Test
{
public static Entity entity = new Entity();
public static void Main(string[] args)
{
var objectHandler = Activator.CreateInstance(null,
args);
var obj = objectHandler.Unwrap();
entity.GetAnnotation(obj.GetType());
}
}
}
Entity.cs
using System;
namespace Demo
{
public class Entity
{
public void GetAnnotation(Type classname)
{
Attribute[] dataAnnotationlist = Attribute.GetCustomAttributes(propInfo);
foreach (var dataannotationAttribute in dataAnnotationlist)
{
//some operation to get annotation property from Employee.cs class
}
}
}
}
Employee.cs
using System.ComponentModel.DataAnnotations;
namespace Demo
{
public class Employee
{
[Display(Name = "name")]
public string name { get; set; }
}
}
I have created XML file format from class file (Employee.cs) using reflection. But error occurred when try to run through Command Prompt. It runs in visual studio.
I want to run Test.cs, Entity.cs using command prompt with passing "Employee.cs" as a string parameter to Main method. Now, I have passed hard coded as,
System.Runtime.Remoting.ObjectHandle objectHandler = Activator.CreateInstance(null, "Demo.Employee");
Its working fine but how to pass it through command.
Error Occurred is:
Entity.cs(8,29): error CS0234: The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) Entity.cs(9,19): error CS0234: The type or namespace name 'Objects' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) Employee.cs(6,33): error CS0234: The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?)
and it also shows error for "DataAnnotations" and "Objects".
how can i solve this problem?
One option to simply build .csproj with MSBUILD .
More entertaining is to configure all dependencies yourself via command line arguments of csc. For your immediate error you need to add references with /r:
command similar to following
csc /out:Test.exe /r:System.ComponentModel.DataAnnotations.dll *.cs
For more details on command line arguments of csc check help csc /?
or on MSDN CSC command line options and Building with CSC .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.