Can't use System.Management.Automation in C# Visual Studio - c#

I'd made a simple C# console app in Visual Studio 2019.
I would like to use the Automation.dll so I installed the Automation package.
https://www.nuget.org/packages/System.Management.Automation
I sat the System.Management.Automation using but it doesn't work.
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Collections.ObjectModel;
using System.Management;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
}
This is the error (translated from German)
CS0234 The type or namespace name "Automation" does not exist in the namespace "System.Management". An assembly reference may be missing.

Related

WPF WebHostBuilder does not contain definition for UseKestrel

I am trying to implement single sign on using OIDC as per GitHub but I keep getting the error:
'WebHostBuilder' does not contain a definition for 'UseKestrel' and no accessible extension method 'UseKestrel' accepting a first argument of type 'WebHostBuilder' could be found (are you missing a using directive or an assembly reference?)
when implementing the SystemBrowser.cs code
using IdentityModel.OidcClient.Browser;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
//other code
//simplified code extract below
IWebHost _host = new WebHostBuilder()
.UseKestrel()
.UseUrls(_url)
.Configure(Configure)
.Build();
//other code
According to this it should be part of the Microsoft.AspNetCore.Hosting?
Is there something I'm missing or a NuGet package I need installing? The packages installed so far are:
Any assistance would be appreciated.
The default asp.net core application could work well because the Microsoft.AspNetCore.Hosting package and other related package integrated in the framework.
I test a console application with asp.net core and reproduce your issue.Install the Microsoft.AspNetCore.Hosting together with Microsoft.AspNetCore.Server.Kestrel.
You could download on NuGet Package Manager by searching for the package name or download on Package Manager Console by using the command in the following reference:
https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/2.2.0?_src=template

How to debug c# project on Mono using comand line using Windows os

I downloaded Mono from the oficial website, I added path using CMD: setx path "%path%;C:\Programs\Mono\bin" and then I opened Mono to see comands. I wrote a code using notepad to test it:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world!");
Console.ReadLine();
}
}
}
I named it into mis.cs and now I want to debug it!
I wrote cd C:/Users... and than I tried first mono mis.cs but said that Cannot open assembly 'mis.cs': File does not contain a valid CIL image. And than I wrote mono --debug mis.cs and said the same. I tried also with 'mono --debug mis.cs -o mis.exe' and same.
What should I do? I don't want to use Microsoft VS. I want to use the old method.

Chome opens for a split second then closes using selenium webdriver

I’m setting up chromedriver (win32) on visual studio using C#, I have firefox and it works great. I have downloaded the chromedriver.exe and set the PATH in windows to its location (C:...misc...\Selenium Webdriver\chromedriver) as the book “selenium recepies in C sharp” suggests. I am able to open up the driver via cmd and see the port. I have also used the NuGet package manager to get the chromewebdriver there. I have looked at this link with no success.
Chrome open for a split second and then closes.
My code.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[TestClass]
public class BrowserTest
{
[TestMethod]
public void ChromeTest()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
I’m willing to remove everything and start from scratch if I’ve botched the install somewhere along the way. Any help would be great.
EDIT: I have uninstalled and reinstalled chrome also.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;
namespace UnitTestProject1
{
[TestClass]
public class BrowserTest
{
string DRIVER_PATH = #"C:...misc...\Selenium Webdriver\chromedriver";
[TestMethod]
public void ChromeTest()
{
IWebDriver driver = new ChromeDriver(DRIVER_PATH);
driver.Navigate().GoToUrl("http://www.google.com");
}
}
}
I am new to selenium. As per tutorial I installed Web Driver for Google Chrome i.e WebDriverChromedriver. On running the sample program I got the same issue.
Then I installed "Selenium.Chrome.WebDriver" package from Nugetpackage. And my program got executed successfully.

Chrome Driver issues in C# selenium

I wrote my first selenium script and it worked. here is the code below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace test1Sel
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver(#"C:\ChromeDriver");
If i try and write a new script however i get an error on the driver saying Invalid argument has been supplied. I am using Visual Studio 2013 Pro. I am not sure why the line worked the first time but will not work in any other script. i have installed both selenium packages in the first script and in any other test script i have tried. any ideas would be great!
Try to replace Chrome driver into the bin folder (solution\project\bin\debug), and use constructor without path (without arguments).
IWebDriver driver = new ChromeDriver();

Why does WebRequestMethods not exist in the current context?

I'm using Visual Studio 2012 and playing around with Windows Phone 7.1 application development. This is a newly-created project.
When I use this code, why do I get this error?
The name 'WebRequestMethods' does not exist in the current context
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
...
public MainPage() {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Method = WebRequestMethods.Http.Post;
}
...
It seems like it can't recognise that WebRequestMethods is a part of System.Net. It also fails if I specify System.Net.WebRequestMethods.Http.Post.
System.Net.WebRequestMethods.Http isn't available in the .NET Profile for Windows Phone, though it may not be readily apparent depending on which documentation page you're looking at. Just set it to the string value "POST".
I have some additional context in my blog article: Windows Runtime-What's supported Where?

Categories

Resources