Visual Studio 2013 - C# - IHttpActionResult cannot be found - c#

Trying to build the test project below, I get this error:
Error: The type or namespace name 'IHttpActionResult' could not be
found (are you missing a using directive or an assembly reference?)
In the "Reference Manager" dialog, Assemblies/Framework, I ticked the System.Web.Http box.
Here is the source:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
namespace dotNET45_test
{
class Program {
static void Main(string[] args) { }
}
class Test : IHttpActionResult { // <-- Error
}
}
Is anything missing in the source code, or in the project settings?

Related

Xamarin Workbooks: Use of namespaces

I want to try out Xamarin Workbooks. Thereby I choose Console with the following code:
using System;
using System.Linq;
using System.Xml.Linq;
I get
(3,18): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Xml' (are you missing an assembly reference?)
Isn't this namespace supported or what I'm doing wrong? I can't add a reference to System.Xml.dll only NuGet packages.
You can manually reference assemblies via the #r instruction:
Example:
#r "System.Xml.Linq"
using System;
using System.Linq;
using System.Xml.Linq;
var firstOneInList = (new List<string> {
"foo", "foo2"
}).First<string>();
Try using Load instead:
#r "System.Xml.Linq"
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
var xdoc = XDocument.Load("C:\Users\some-user\Desktop\xmlResponse.txt‌​");

Convert LinqPad C# Program to Visual Studio C# Console Program

This seems obvious but I cannot see an easy way to to do this.
I have written a C# Program in LinqPad and it runs well, is there a guide for moving this to a Visual Studio Console Program.
A simple program such as this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DataContext dataContext = this;
var products = dataContext.GetTable<Product>();
var query = from p in products
select p;
query.Dump();
}
}
}
produces these errors:
Error 1 The type or namespace name 'DataContext' could not be found (are you missing a using directive or an assembly reference?) c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
Error 2 Keyword 'this' is not valid in a static property, static method, or static field initializer c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs
Error 3 The type or namespace name 'Product' could not be found (are you missing a using directive or an assembly reference?) c:\users\xxx\documents\visual studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 14 49 ConsoleApplication1
I must have to add some references, add a connection to the database, I just need a guide for what to add to my project but I cannot find one.

How to reference a class in a subfolder and different namespace?

I'm creating a tiny app that has the following directory structure:
GUI
- MainWindow.cs
Model
Resources
Utilities
Program.cs
MainWindow.cs is inside GUI folder and its namespace is OrtizOL.BackupTimer.GUI , by other hand, Programs.cs is inside the root directory and its namepace is OrtizOL.BackupTimer.
BTMainWindow.cs file:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace OrtizOL.BackupTimer.GUI
{
public partial class BTMainWindow : Form
{
// code ...
}
}
Program.cs file:
using System;
using System.Windows.Forms;
using OrtizOL.BackupTimer.GUI;
namespace OrtiOL.BackupTimer
{
public class Program
{
public static void Main ()
{
Application.Run (new BTMainWindow() );
}
}
}
But, when I need to compile using this command:
csc /t:winexe /out:OrtizOLBackupTimer.exe /recurse:GUI *.cs
It doesn't work. Error message:
CS0246: The type or namespace name 'OrtizOL' could not be found (are you missing a using directive or an assembly reference?)
Do I need to make an assembly of BTMainWindow first? What is correct way to reference a class in a sub-directory?
Thanks in advance?
For the code you posted you have the namespace for BTMainWindow declared as OrtizOL.BackupTimer not OrtizOL.BackupTimer.GUI
You have to correct the namespace of class BTMainWindow from namespace OrtizOL.BackupTimer to:
namespace OrtizOL.BackupTimer.GUI

The type or namespace name 'Window' does not exist in the namespace 'System.Windows'

I am trying to write an extension method for the WPF Window class. I am doing it in a class library project in my solution, so that I can use it in all my projects in the solution.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace ExtensionMethods
{
public static class MyExtensions
{
public static void ResizeToPrimaryScreenWorkingArea(this System.Windows.Window w)
{
}
}
}
When I try to compile this, I get the following error:
The type or namespace name 'Window' does not exist in the namespace
'System.Windows'
Yes, I DID add references to System.Windows and System.Windows.Forms in my class library project, and they are showing under References in the project in Solution Explorer.
What am I doing wrong?
Add PresentationFramework.dll reference to your project it contains the System.Windows namespace.
http://msdn.microsoft.com/es-es/library/system.windows.window(v=vs.110).aspx

Couldn't find modelDataContext

Im trying to use LINQ in my ASP.NET/C# website. For that I need to access the class 'modelDataContext' which is a part of the LINQ namespace.
Im using Visual Studio 2010 Professional
This is my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class admin_new_feed : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
modelDataContext data = new modelDataContext();
}
}
Full error message I get
Error 1 The type or namespace name 'modelDataContext' could not be
found (are you missing a using directive or an assembly
reference?)
Things i've tried, which doesn't solve problem
Adding the reference (Right-click solution, add reference - System.Data.Linq)
Re-create the website
Right clicking on the line, to see if the tab "Resolve" was there. But it wasn't.

Categories