-1

I have one Windows 7 machine that throws "Object reference not set to an instance of an object" when ASP.NET tries to start up. I have 2 other Windows 7 machines and a Windows 10 machine where this same code works fine. It would appear that something about that machine won't let ASP.NET startup, but I don't know why. I have tried turning off Windows firewall, turned off his anti-virus software, put files in a different folder in case of weird permissions issues, tried changing to non-SSL server, and nothing I can think of will fix this issue with this one machine. The worst part about this is that the error is happening inside the WebHostBuilder's Run function so I can't really see why it is doing it.

This computer cannot run ASP.NET Core no matter whether it is my project or a fresh ASP.NET Core .NET 4.52 project, so I know that it has nothing to do with my code. My guess is that I could reformat that Windows 7 machine and reinstall Windows 7 and it probably would work fine, but I really would like to know why it is failing instead. I am wary of going to production if a certain percentage of computers simply cannot run my software especially since I don't know how often this will happen.

Anyone have any ideas what I could try to resolve this? A null reference exception is so vague I am at a loss about where to go from here.

Stack trace for outer exception:

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait(TimeSpan timeout) at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.DisposeListeners(List1 listeners) at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address) at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication1 application) at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start() at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage) at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token) at DBA.Server.ServerAppService.b__1_0()

Stack trace for inner exception:

at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.d__19.MoveNext()

Sorry about stack trace formatting...

Edit 4: I have reformatted my question now that I know the machine in question fails even when none of my code is involved and I am running the standard ASP.NET Core project template.

Greg Cobb
  • 466
  • 6
  • 15
  • 1
    Without seeing any startup code, we are at an even greater loss than you are. – David L Sep 26 '16 at 20:16
  • Fair enough. I take some of the relevant snippets of code and post them. – Greg Cobb Sep 26 '16 at 20:17
  • Can you attach a remote debugger to see what variable is null? Also, add sufficient `Trace.WriteLine`s and listen to them with DebugView. Then try to see which variable is null. – Patrick Hofman Sep 26 '16 at 20:33
  • I am not familiar with "Trace.WriteLines and listen to them with DebugView. Then try to see which variable is null." so I am going to go research that real quick and get back to you. I have run a remote debugger which is why I know that it is the "host.Run(_cts.Token);" line inside ServerAppService class that is throwing the error. But I can't dive in to host.Run because it inside a 3rd party library. I'm getting desperate enough I might just end up figuring out how to compile ASP.NET Core from source so I can debug in to it. I'm sure if I could trace into it the answer would show itself. – Greg Cobb Sep 26 '16 at 20:39
  • At least you have the call stack than which might help. Also, take pieces from your code until you have nothing left. In that way you can rule out it is your code failing. – Patrick Hofman Sep 26 '16 at 20:43
  • 1
    I'm going to grab the stack trace from a remote debug and add it to the question. Then I am going to create a new ASP.NET Core project (api template) and test it out on the machine in question. I suspect it will fail as well, but maybe it is some code I added that is causing this and maybe a fresh ASP.NET Core app with work. – Greg Cobb Sep 26 '16 at 20:55
  • 1
    @Fyndor I reopened. The first version had nothing for us to help you with, so the only thing we could do to help was close as that duplicate. I guess your task is the problem, so try to see if you can narrow it down there. – Patrick Hofman Sep 26 '16 at 21:17
  • You gotta be careful about flashing the NRE around here, you can imagine how many debug-my-code-for-me questions come down the road every day... –  Sep 26 '16 at 21:18
  • Per the last edit I just made, this machine is failing with the default ASP.NET Core using 4.52 framework project template without any additional code added. I literally created a new project and hit build without touching anything. I am tempted to remove all my code from the question because the issue obviously is not with my code. – Greg Cobb Sep 26 '16 at 21:20
  • @Will Oh I'm sure. I wouldn't have bothered if it was in my own code, it it really didn't like it was and now I have proved it is not. It is occurring in a somewhat widely used 3rd party library so I thought I would ask the community to see if anyone has seen something similar. – Greg Cobb Sep 26 '16 at 21:23
  • I edited the question again removing references to my code. I went to another dev machine with the latest .NET core sdk installed and created a new project. When I copied the files and ran them on the bad machine it still was failing even though it is just ASP.NET core hello world app running on the latest builds of Core libraries and SDK. This is an issue with the environment running the code (i.e. the bad machine) and possibly a ASP.NET Core bug. – Greg Cobb Sep 26 '16 at 23:23

1 Answers1

1

ASP.NET Core running under the full .NET framework requires .NET 4.5.1+ to be installed. If you instead only have .NET 4.5 installed you will get the "Object reference not set to an instance of an object" error when calling the Run method on WebHostBuilder.

Greg Cobb
  • 466
  • 6
  • 15
  • Same for net5 if you only have 4.8 installed (i.e. vanilla Windows Server) and didn't compile with `--self-contained true` so either install a net5 (asp-)runtime or ship a self contained version. – mbx Jan 26 '21 at 09:49
  • Well this is a little bit different. I was running ASP.NET Core with full framework. You are talking about ASP.NET Core running on .NET Core. .NET 5 is actually .NET Core rebranded to "simplify" the numbering system and because Core is where all dev is focused now. 4.8 is full framework whereas .NET 5 is Core. Its a bit confusing really. And recent versions of ASP.NET Core no longer even run on full framework so whatever version of ASP.NET Core you use you will need the corresponding .NET Core SDK to compile. – Greg Cobb May 17 '21 at 18:05
  • I'm totally aware of the Net5 being netcore5 situation and thought it to be known implicitly, but other readers may not. So thanks for pointing that out. Point was: If you depend on netcore5 (or any other core) you have to either install/ship netcore or provide a self contained build as NETFX is orthogonal to netcore. – mbx May 19 '21 at 09:06