TheAngryByrd / MiniScaffold

F# Template for creating and publishing libraries targeting .NET 6.0 `net6.0` or console apps .NET 6.0 `net6.0`.
https://www.jimmybyrd.me/MiniScaffold/
MIT License
267 stars 31 forks source link

WatchDocs null reference exception #194

Closed halcwb closed 4 years ago

halcwb commented 4 years ago

Describe the bug When trying to 'watch' the docs, I got a null reference exception.

To Reproduce Steps to reproduce the behavior:

  1. Create a project using the template
  2. Run the WatchDocs target
  3. Refresh the browser after opening the docs page

Expected behavior Reload of the page

Screenshots The cmd line shows:

Hosting environment: Production Content root path: C:\Development\lab\MiniScaffold\docsTool\bin\Debug\netcoreapp3.1\ Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Program.WebServer.openBrowser(String url) in C:\Development\lab\MiniScaffold\docsTool\Program.fs:line 510 at Program.WebServer.serveDocs@515.Invoke(Unit unitVar) in C:\Development\lab\MiniScaffold\docsTool\Program.fs:line 516 at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation1 ctxt, TResult result1, FSharpFunc2 part2) in E:\A_work\130\s\src\fsharp\FSharp.Core\async.fs:line 398 at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109 --- End of stack trace from previous location where exception was thrown --- at Microsoft.FSharp.Control.AsyncPrimitives.Start@907-1.Invoke(ExceptionDispatchInfo edi) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 907 at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc2 firstAction) in E:\A_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109 at Microsoft.FSharp.Control.TrampolineHolder.ExecuteWithTrampoline(FSharpFunc2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 177 at <StartupCode$FSharp-Core>.$Async.-ctor@163-1.Invoke(Object o) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 165 at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action1 callback, TState& state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() watch : Exited with error code -532462766 watch : Waiting for a file to change before restarting dotnet...

Workaround Wrapping the below code in a try catch resolves the issue:

    let openBrowser url =
        //https://github.com/dotnet/corefx/issues/10361
        try
            let psi = ProcessStartInfo(FileName = url, UseShellExecute = true)
            let proc = Process.Start psi
            proc.WaitForExit()
            if proc.ExitCode <> 0 then failwithf "opening browser failed"
        with
        | _ -> printfn "cannot open browser"

Desktop (please complete the following information): .NET Core SDK (reflecting any global.json): Version: 3.1.102 Commit: 573d158fea

Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.102\

Host (useful for support): Version: 3.1.2 Commit: 916b5cba26

.NET Core SDKs installed: 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 2.2.401 [C:\Program Files\dotnet\sdk] 2.2.402 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.102 [C:\Program Files\dotnet\sdk]

Smartphone (please complete the following information): NA

Additional context Add any other context about the problem here.

TheAngryByrd commented 4 years ago

Maybe I should have followed the advice of the comment of that dotnet issue I have in that code 😂