Xamarin Workbooks: Use of namespaces - c#

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‌​");

Related

Visual Studio 2013 - C# - IHttpActionResult cannot be found

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?

c# | the type or namespace ParamaterizedThreadStart does not exist

Okay so essentially this is happening:
I am trying to run a
Thread tcpHandlerThread = new ParamaterizedThreadStart(tcpHandler);
but I get the error
the type or namespace ParamaterizedThreadStart does not exist
on ParamaterizedThreadStart but I have these imports:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
Sorry if this is a stupid question :\ What imports am I missing or is it just an error with my Visual Studio?
ParameterizedThreadStart is a delegate.
use this instead..
Thread tcpHandlerThread = new Thread(tcpHandler);
If you want to run methods with parameters. you can use this..
Thread tcpHandlerThread = new Thread(() => tcpHandler(parameters));
It looks like you misspelled the ParameterizedThreadStart class.
The link below might help you and has a good example how to create a parameterized thread.
https://msdn.microsoft.com/en-us/library/1h2f2459%28v=vs.110%29.aspx

Error while trying use project's classes into another project

i have this structure:
Entity:(It's a Project named "Entity" - type: ClassLib)
Class 1;
Class 2;
Class 3;
DataBase:(It's a Project named "DataBase" - Type: ClassLib)
Class 1;
Class 2;
Class 3;
MainProject: (Windows Form)
Some Forms;
Then what I did was:
Added both projects into MainProject's references
Wrote on the codebehind:
using DataBase;
Worked perfect... But when I try to add the DataBase Project into the codebehind, it doesn't show up while I'm typing and also give me this error:
Error 2 The type or namespace name 'DataBase' could not be found (are you missing a using directive or an assembly reference?)
Ps: All the Classes of the projects (Class 1,2,3...) have the same namespaces wich is the project's name.
I tried some stuff I found on the internet, but nothing worked... Any Idea why?
UPDATE
My Code:
MainProject
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Entity; ( WORKED ! I can acess Entity's Class)
using DataBase; <---------------------------------- (ERROR HERE)

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

XDocument doesn't appear to exist in System.Xml namespace

I'm having what I think will probably be a really simple problem, in developing my first WP7 app I've come to the stage of accessing my Site's api and parsing the XML, however I'm stumbling just at trying to use XDocument.
I search around and found this example code: Load an XML file from a website into XDocument (Silverlight and Windows Phone 7) but the XDocument type does not exist, I understand it is supposed to exist in the System.Xml namespace which I am using, but the error still remains, what have I missed?
Developing on Visual Studio 2010 Express for Windows Phone, code for this class is below:
using System;
using System.Net;
using System.IO;
using System.Xml;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Application
{
public class DataRetriever
{
public void parseNewsXML()
{
WebClient client = new WebClient();
client.OpenReadCompleted += (sender, e) =>
{
if (e.Error != null)
return;
Stream str = e.Result;
XDocument xdoc = XDocument.Load(str);
};
}
}
Exact error being thrown is:
Error 1 The type or namespace name 'XDocument' could not be found (are you missing a using directive or an assembly reference?)
Thanks in advance
For Silverlight, that class is in System.Xml.Linq.dll, according to MSDN - so add a reference to System.Xml.Linq.dll. You will also need a using directive at the top of your code file:
using System.Xml.Linq;
(these are exactly the same two suggestions that the compiler itself makes: "are you missing a using directive or an assembly reference?")

Categories