Why does WebRequestMethods not exist in the current context? - c#

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?

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

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

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.

Selenium automation project is working on localhost but not working production

Here is my code. I have use nuget package selenium, chrome drive and chrome drive exe.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace selenium
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com");
driver.FindElement(By.Name("q")).SendKeys("test");
}
}
}
You need to enable logs and check them. Possible problem may be that browser cannot be started (e.g. Chrome and ChromeDriver are not installed/configured). Another possibility could be that outgoing internet traffic is blocked, what typically happens on servers in production.

How do I build for debug in Visual Studio 2010 Express for C#

I recently started learning C# and found quickly that one exception was not being thrown when I ran my project. The tutorial I was watching mentioned that exceptions work differently in the Release configuration then they do in the Debug configuration so I figured I must be running with the Release configuration.
I found an article on Microsoft's site that indicates how to switch configurations, however I must be missing something in the instructions because I still cannot figure out how to switch settings.
I'm using Visual Studio Express 2010 for C#. Could someone tell me why the exception below is not being thrown and how to fix it?
Here is the code I'm using:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace ReallySimpleLifeCounter
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_testLabel.Content = "Working";
throw new Exception(); //not being thrown
}
}
}
You can set the mode using the configuration manager, it is usually hot keyed F5.
Make sure you have the toolbar 'Standard' selected from there you can select the mode to run the Build {Debug, Release}

Cannot build project using Mono for Android

When i try to build and run my project i get the following build errors:
HourScreen.cs(13,13): Error CS0433: The imported type `System.Net.WebRequest' is defined multiple times (CS0433)
HourScreen.cs(17,17): Error CS0433: The imported type `System.Net.WebResponse' is defined multiple times (CS0433)
The lines on which the errors happen look like this:
WebRequest request = WebRequest.Create(uri);
WebResponse response = request.GetResponse();
I include the following into the project:
using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Preferences;
using Android.Graphics;
I think one of the includes must be playing up but i have no idea which. Removing one causes a huge load of other errors. Can anyone see where im going wrong?
EDIT:
I've included the build log: http://pastebin.com/FrmzfhcY
HourScreen.cs(167,17): error CS0433: The imported type `System.Net.WebResponse' is defined multiple times
/Developer/MonoAndroid/usr/lib/mono/2.1/System.dll (Location of the symbol related to previous error)
/Mono for Android/Bups_Urenverantwoording 1.0/Bups_Urenverantwoording/bin/Debug/System.Net.dll (Location of the symbol related to previous error)
The log has your answer. Mono for Android provides it's own System.Net stack in System.dll but you're also including other assemblies, like System.Net.dll which includes the same type.
Since you also reference System.Windows.dll I assume you're trying to include some code from Silverlight (or Moonlight) and that won't work. At least not for for System.Net.dll (not sure what you're trying to use from System.Windows.dll).

Categories

Resources