Reputation: 3893
I'm trying to build an UWP and instantiate HttpListener
. However, I'm getting the following error in Visual Studio's Error List: Cannot find type System.Net.WebSockets.WebSocketContext in module System.Net.WebSockets.dll
, preventing me from building and running the application.
My application looks as follows:
using System.Net;
using Windows.UI.Xaml.Controls;
namespace HttpTestServer
{
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
private static void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var httpListener = new HttpListener();
httpListener.Prefixes.Add("http://*:9080/");
httpListener.Start();
}
}
}
I believe it's related the minimum Windows version I'm targeting. I'm forced to target Windows 10 Anniversary Update build 10.0.14393.0. How do I know if HttpListener
is included in this version of Windows? According to https://learn.microsoft.com/en-us/dotnet/api/system.net.httplistener?view=netframework-4.8 it should be included in .NET Standard 2.0.
Is it possible to instantiate the HttpListener
somehow anyways?
Upvotes: 0
Views: 166
Reputation: 32775
How do I know if HttpListener is included in this version of Windows?
Derive from official document HttpListener
included in .Net Standard 2.0, and the lowest UWP version that support .Net Standard 2.0 is 16299 (Fall Creators Update), So the you need edit the app's target min version to 16299.
Upvotes: 1