I'm trying to get a simple "Hello World" type WebSocket server running on my Mac using Visual studio for Mac OS X.
Where are the HttpContext.IsWebSocketRequest property and the
HttpContext.AcceptWebSocketRequest method? The documentation appears to say they are in HttpContext inside the System.Web dll but I've referenced that (as well as System.Net) and Visual studio can't find them.
Is there something I'm missing or have forgotten?
This is the code I've that's giving me problems.
using System;
using System.Web;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net.WebSockets;
using System.Collections.Generic;
public void ProcessRequest(HttpContext context)
{
if (context.IsWebSocketRequest)
context.AcceptWebSocketRequest(HandleWebSocket);
else
context.Response.StatusCode = 400;
}
The sample I'm following is: https://github.com/paulbatum/WebSocket-Samples/blob/master/AspNetWebSocketEcho/EchoHandler.ashx.cs
As far as I remember is not supported yet: http://go-mono.com/status/status.aspx?reference=4.5&profile=4.5&assembly=System
You can use one of the many third-party components available for Mono. I develop and maintain one of them https://github.com/vtortola/WebSocketListener
Related
I was recently watching tutorials on C# where they mentioned that specifying either using System and then using Console.WriteLine or writing System.Console.WriteLine if you don't specify using <namespace> was necessary for proper namespace resolution to happen when writing programs otherwise the compilation would fail.
But when I'm using Visual Studio 2022, Console.WriteLine seems to work without specifying any namespace at all.
Is this some optimisation that Visual Studio 2022 does? Why is this working?
On top of this, if I use System.Console.WriteLine, VS 2022 also greys out System and says "name can be simplified".
Try this
using System;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
If you create c# project of asp.netframrwork. It will automatically generate the "using System" namespace.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Program
{
static void Main(string[] args)
{
}
}
}
If your console project is .NET 6 and above. Please refer to Exploring Ideas to Build Code While Learning Using Top-Level Statements.
Hope it helps you.
/* If I am building after deleting Newtonsoft.Json.dll then It works fine but after clean and build getting the same error?*/
using System;
using System.Web;
using System.Data;
using System.Collections;
using localhost;
using System.Text;
using System.Collections.Generic;
using System.Net.Mail;
using System.Net;
using BusinessLayerGDS.Model;
using BusinessLayerGDS.BAL;
using System.IO;
using System.Security.Cryptography;
using System.Linq;
using System.Configuration;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Xml;
**And The codes:**
Newtonsoft.Json.Linq.JObject objActualData=Newtonsoft.Json.Linq.JObject.Parse(strResponse);
What you need to do is go to:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Or where this folder is in your computer:
>
Temporary ASP.NET Files
I have seen some people configuring it under:
c:\Users[youruserid]\AppData\Local\Temp\Temporary ASP.NET Files
Or you may be using a different .net version than v4.0.30319
Inside this folder you may find some odd folder names one of those is the folder of your application, you need to find which on it is then you should delete what's inside the bin
If some files or folders are locked you may need to stop your IIS or IIS Express.
Go to back and rebuild your application; it should work fine then
Close VS
Open your .csproj file with a text editor
Look for all the hintpath tags for Newtonsoft
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
Fix the hintpaths ALL - look carefully, it can be configured at multiple locations and Nuget was not bulletproof for me anyawy.
When I run this code:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using Sikuli4Net.sikuli_REST;
using Sikuli4Net.sikuli_UTIL;
using SikuliModule;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Sikuli
{
class Program
{
static void Main(string[] args)
{
driver = new ChromeDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("https://www.google.co.nz/");
Thread.Sleep(2000);
String image = #"C:\Users\safa\Desktop\gmail.jpg";
SikuliAction.Click(image);
}
}
}
I got this exception:
System.ComponentModel.Win32Exception:
'The system cannot find the file specified'
I changed file location but again I got same error.
This the image that I want to click on:
Run the visual studio as administrator using below steps
Click on start(windows) button
Type Visual Studio
Mouse Right Click on Visual Studio
Click on Run as Administrator option
I think there is no mistakes in code. So try this once.
Increase the wait time to 5000ms
For this program you don't need Sikuli4Net, remove usings related to that
I'm working on Matlab and C# projects, I've created a DLL file from the Matlab project and run it on the C# project.
My code works fine on my computer and on any Windows 7 x64 bit that I've tested.
The problem is with Windows 8, When I'm trying to run my app on Win 8 PC the app collapsed while calling to the main class that included in the DLL.
I tried to catch the error, but no error occurred, the app just crashed.
I've already installed MCR for the specific Matlab version, but it still doesn't work.
I believe that I'm missing some system configuration, can someone help to do some order what exactly should I do in order to run it?
UPDATE1:
The code:
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.IO;
using VisionCameraQA;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
namespace VisionCameraQATest
{
public partial class Form1 : Form
{
cls_Main main;
public Form1()
{
InitializeComponent();
try
{
main = new cls_Main();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString())
}
}
}
}
The app crashes while getting to main = new cls_Main();, it is not reached to the catch at all.
I want to use Appium to make automated testing for my Android app. I downloaded the Appium for Windows and could run my app on device from within appium.exe. Now I want to write test cases in C# which make use of selendroid integrated in Appium. I googled a lot but couldn't find any example demonstrating the same. I found one project on github but it's giving a lot of compiler errors. Could anybody guide me about how to write test cases using Appium in C#? If you have any resources, please provide me the same. Thanks.
You can go with installing Visual Studio 2012 or visual express for web. Use NUnit framework to write the test cases and execute them as a class library project in that.
1) Create a class library project and create a new class e.g "Class1". Add the packages as provided in the links above. Try the below code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using NUnit.Framework;
using OpenQA.Selenium.Interactions;
using System.Threading;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.MultiTouch;
using OpenQA.Selenium.Appium.Interfaces;
using System.Drawing;
namespace ClassLibrary2
{
[TestFixture]
public class Class1
{
public AppiumDriver driver;
public DesiredCapabilities capabilities;
public Class1()
{
Console.WriteLine("Connecting to Appium server");
capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.BrowserName, "Android");
capabilities.SetCapability(CapabilityType.Platform, "Windows");
capabilities.SetCapability(CapabilityType.Version ,"4.1.2");
capabilities.SetCapability("Device", "Android");
//Application path and configurations
driver = new AppiumDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);
}
[Test]
public void login()
{
driver.FindElement(By.Name("Country")).Click();
//Your further code as per the application.
}
Then Build a solution for your project and run it in NUnit.