Minimal Console errors out with: Object reference not set to an instance of an object.
See original GitHub issueError
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.Owin.Hosting
StackTrace:
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.FromConfigImplementation..ctor()
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.<LoadFromConfig>b__0()
at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Func`1 valueFactory)
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.LoadFromConfig(IDictionary`2 settings)
at Microsoft.Owin.Hosting.Engine.StartContext..ctor(StartOptions options)
at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options, Action`1 startup)
at Program.<Main>$(String[] args) in C:\Projects\personal\Delete\TestServer\Program.cs:line 7
Just run the following code.
using Microsoft.Owin.Hosting;
using Owin;
string BaseUri = @"http://localhost:19000";
List<string> payloads = new();
var builder = WebApp.Start(BaseUri, app =>
{
app.Run(async context =>
{
using StreamReader reader = new(context.Request.Body, System.Text.Encoding.UTF8);
context.Request.Body.Position = 0;
payloads.Add(await reader.ReadToEndAsync());
context.Response.ContentType = "application/json";
await context.Response.WriteAsync(@"{""Success"":true}");
});
});
Console.In.ReadLine();
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.9" />
</ItemGroup>
</Project>
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Object Reference Not Set to an Instance of an Object
This exception is thrown when you try to access a member—for instance, a method or a property—on a variable that currently holds a...
Read more >c# - Object reference not set to an instance of an ...
Consider this code: String s = null; Console.WriteLine(s.Length);. This will throw a NullReferenceException in the second ...
Read more >Error: "Assign: Object reference not set to an instance of ...
Hi, so basically I want to loop through every sheet that exists in a workbook. Then, I found this specific solution: How to...
Read more >Fix: "Object Reference Not Set to an Instance of ...
This error code will show when a Microsoft Visual Studio object is missing, categorized as null, or cannot be accessible.
Read more >Backups fail with error: Object reference not set to an ...
I only have full system backups. Would you like me to try a new backup job with a small set of files to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For migration you’re better off using the OWIN shim in AspNetCore to run on the servers there. That way you don’t need to bring in extra libraries like HttpListener which we know aren’t compatible.
@vandanv Selfhost doesn’t work on net5/6. You can host it under kestrel in the asp.net core pipeline as shown in my example. It should also work under IIS.