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.
Related
RE: DotNet 6.0 and VS Community 2022 (64-bit) - CurrentVersion 17.1.1
This code results in a compiler error CS0246:
using GloboTicket.TicketManagement.Domain.Entities;
namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
public interface IOrderRepository: IAsyncRepository<Order>
{
}
}
This following code does not (note the use of the prefix "Persistence." to refer to IAsyncRepository):
using GloboTicket.TicketManagement.Domain.Entities;
namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
public interface IOrderRepository: Persistence.IAsyncRepository<Order>
{
}
}
Why is this needed? IAsyncRepository and IOrderRepository are siblings in the same folder - i.e., in the same namespace!
The reference can be used without the "Persistance." prefix if the "where T : class" is deleted in the base type "IAsyncRepository":
namespace GloboTicket.TicketManagement.Application.Contracts.Persistence
{
public interface IAsyncRepository<T> where T : class
{
/...
}
}
How to resolve Errors of below code?
Code
namespace Phonebook
{
using System;
using System.Data.Entity;
14- using System.Data.Entity.Infrastructure;
17- public partial class ContactsEntities : DbContext
{
public ContactsEntities()
20- : base("name=ContactsEntities")
{
}
24- protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Tbl_Contacts> Tbl_Contacts { get; set; }
public class DbSet<T>
{
internal object Tolist;
}
}
}
Errors
Error CS0115 'ContactsEntities.OnModelCreating(DbModelBuilder)': no
suitable method found to override Phonebook
C:\Users\PC\Desktop\Phonebook\ Phonebook \ModelContacts.Context.cs 24
Error CS0234 The type or namespace name 'Infrastructure' does not
exist in the namespace 'System.Data.Entity' (are you missing an
assembly reference?) Phonebook C:\Users\PC\Desktop\ Phonebook \
Phonebook \ModelContacts.Context.cs 14
Error CS0246 The type or namespace name 'DbModelBuilder' could not be
found (are you missing a using directive or an assembly reference?)
Phonebook C:\Users\PC\Desktop\
Phonebook\Phonebook\ModelContacts.Context.cs 24
Error CS0246 The type or namespace name 'DbContext' could not be
found (are you missing a using directive or an assembly reference?)
Phonebook C:\Users\PC\Desktop\ Phonebook\ Phonebook
\ModelContacts.Context.cs 17
Error CS1729 'DbContext' does not contain a constructor that takes 1
arguments Phonebook C:\Users\PC\Desktop\ Phonebook \Phonebook
\ModelContacts.Context.cs 20
My problem has been resolved :
I added EntityFramework to project from Nuget packages in visualStudio and I Performed ' Powershell ' settings in control panel .
The Xamarin.Auth project broke up i.e. the source code was compiling OK and after another Xamarin.Android update it was suddenly broken.
It turned out that the problem arose after the Mono.Android.dll (Xamarin.Android) was extended by several namespace definitions.
I hunted the problem down to the following:
There is a dll #1 (Mono.Android.dll):
namespace Xamarin.Android
{
public class Class1
{
}
}
namespace Android.OS
{
public class Class2
{
}
}
There is a dll #2 (Xamarin.Auth.Android.dll):
namespace Xamarin.Auth
{
//This does not compile. See the problem description below.
public class User1 : Android.OS.Class2
{
}
}
Intellisense shows the following problem:
Error CS0234 The type or namespace name 'OS' does not exist in the namespace 'Xamarin.Android' (are you missing an assembly reference?)
This can be fixed by changing the latter namespace to something else or by using the global:: identifier:
namespace SomeOtherNamespace
{
//This compiles ok.
public class User1 : Android.OS.Class2
{
}
}
namespace Xamarin.Auth
{
//This compiles ok.
public class User1 : global::Android.OS.Class2
{
}
}
The question is: why does not intellisense give a warning that the Android namespace branch is ambiguous between global::Xamarin.Android and global::Android? What is the good way out of it? Always use global:: namespace identifier?
You can use the global directive to tell the compiler it should evaluate the namespace from the root, else it tries to evaluate the namespace relative from the current namespace. Using global always uses the full qualified namespace name, so that is why it works when you prefix it.
Another option would be using an alias:
using AOS = Android.OS;
namespace Xamarin
{
public class User1 : AOS.Class2
{
}
}
I've added both a Web Service and a Web Reference to my project and can consume neither (one of which I named emsBookings) appropriately because I get the following error:
Compiler Error Message: CS0246: The type or namespace name 'emsBookings' could not be found (are you missing a using directive or an assembly reference?)
I tried using:
using emsBookings;
But that did not resolve the issue - and instead the error pointed to that line when I added that code.
My code looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
public string xmlRequest;
protected void Page_Load(object sender, EventArgs e)
{
WebApplication1.emsBookings.GetAllBookingsRequestBody client = new WebApplication1.emsBookings.GetAllBookingsRequestBody();
//inputs required for request
string username = "theusername";
string password = "thepassword";
DateTime startDate = System.DateTime.Today;
DateTime endDate = System.DateTime.Today;
int buildingID = 36;
bool viewCombo = false;
client.UserName = username;
client.Password = password;
client.StartDate = startDate;
client.EndDate = endDate;
client.BuildingID = buildingID;
client.ViewComboRoomComponents = viewCombo;
emsBookings.GetAllBookingsRequest request = new emsBookings.GetAllBookingsRequest();
request.Body = client;
xmlRequest = request.Body.ToString();
}
}
}
Is there a specific way I need to reference the web-reference and/or web-service in order to use it in my code?
In Web.Config I find reference to emsBookings in the following:
<configuration>
//Extra stuff removed for brevity
<appSettings>
<add key="emsBookings.Service" value="https://my.fully.qualified.server/THEAPI/Service.asmx"/>
I've tried:
rebuilding (no success)
cleaning / rebuilding (no success)
adding 'using emsBookings;' (no success)
Any other ideas on what to try?
I'm fairly limited in my access to the server, so digging through logs in the root C: drive or things like that I would like to try to avoid if possible.
This is not a duplicate as far as I can tell as I am targeting .NET 3.5 and in the Property Pages, the build Target Framework is .NET Framework 3.5; I cannot find any reference to a Client Profile anywhere which was the indicated issue in the other 'possible duplicate' question.
Here is a link to the VS2010 showing the service reference added to my application: http://imgur.com/hIOCqKJ
Here is a link showing that the service reference exists in the same namespace (object browser): http://imgur.com/GcJ133p
Here is some of the Reference.cs:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace WebApplication1.emsBookings {
using System.Runtime.Serialization;
using System;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfInt", Namespace="http://DEA.EMS.API.Web.Service/", ItemName="int")]
[System.SerializableAttribute()]
public class ArrayOfInt : System.Collections.Generic.List<int> {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.CollectionDataContractAttribute(Name="ArrayOfString", Namespace="http://DEA.EMS.API.Web.Service/", ItemName="string")]
[System.SerializableAttribute()]
public class ArrayOfString : System.Collections.Generic.List<string> {
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://DEA.EMS.API.Web.Service/", ConfigurationName="emsBookings.ServiceSoap")]
public interface ServiceSoap {
// CODEGEN: Generating message contract since element name GetAPIVersionResult from namespace http://DEA.EMS.API.Web.Service/ is not marked nillable
[System.ServiceModel.OperationContractAttribute(Action="http://DEA.EMS.API.Web.Service/GetAPIVersion", ReplyAction="*")]
WebApplication1.emsBookings.GetAPIVersionResponse GetAPIVersion(WebApplication1.emsBookings.GetAPIVersionRequest request);
I noticed from your screenshot that you have created a website and that is referenced in the solution?
If you have, its better to create an ASP.NET Web Application and create the service reference again, as from what you have explained.
I have performed my own suggestion the reference has worked as expected.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Please help me in removing Mock error in bold letters.
Error 1 The type or namespace name 'Mock' could not be found (are you
missing a using directive or an assembly
reference?) C:\Users\MOB140003208\documents\visual studio
2012\Projects\RockPaperScissors\RockPaperScissorsTest\Tests\GameTest.cs 65 34 RockPaperScissorsTest
Error 2 The type or namespace name 'Mock' could not be found (are you
missing a using directive or an assembly
reference?) C:\Users\MOB140003208\documents\visual studio
2012\Projects\RockPaperScissors\RockPaperScissorsTest\Tests\GameTest.cs 77 34 RockPaperScissorsTest
Error 3 The type or namespace name 'Mock' could not be found (are you
missing a using directive or an assembly
reference?) C:\Users\MOB140003208\documents\visual studio
2012\Projects\RockPaperScissors\RockPaperScissorsTest\Tests\GameTest.cs 89 34 RockPaperScissorsTest
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RockPaperScissors;
namespace RockPaperScissorsTest.Tests
{
/// <summary>
/// Summary description for GameTest
/// </summary>
[TestClass]
public class GameTest
{
public GameTest()
{
//
// TODO: Add constructor logic here
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void ReturnsCorrectMessageIfPlayerWins()
{
var engineMock = new **Mock**();
engineMock.Setup(de => de.Result(Move.Rock, Move.Paper)).Returns(GameResult.PlayerWins);
var game = new Game(engineMock.Object);
game.PlayerMove = "Paper";
var result = game.Result();
engineMock.VerifyAll();
Assert.AreEqual("Player Wins!", result);
}
[TestMethod]
public void ReturnsCorrectMessageIfComputerWins()
{
var engineMock = new **Mock**();
engineMock.Setup(de => de.Result(Move.Rock, Move.Scissors)).Returns(GameResult.ComputerWins);
var game = new Game(engineMock.Object);
game.PlayerMove = "Scissors";
var result = game.Result();
engineMock.VerifyAll();
Assert.AreEqual("Computer Wins!", result);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ThrowsErrorIfPlayerMoveIsNotSet()
{
var engineMock = new **Mock**();
var game = new Game(engineMock.Object);
game.Result();
}
}
}
are you missing a using directive or an assembly reference?
Yes you are. You need to add a reference to the assembly containing the Mock type. You also need to add a using statement to be able to use the Mock type without having to add the namespace in front.
So make sure that you have a reference to the Moq assembly (preferably by using NuGet) and make sure that you add using Moq; at the top of your source code.