Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WatchDocs null reference exception #194

Closed
halcwb opened this issue Feb 27, 2020 · 1 comment · Fixed by #195
Closed

WatchDocs null reference exception #194

halcwb opened this issue Feb 27, 2020 · 1 comment · Fixed by #195

Comments

@halcwb
Copy link
Contributor

halcwb commented Feb 27, 2020

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 [email protected](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 [email protected](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>[email protected](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
Copy link
Owner

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

@TheAngryByrd TheAngryByrd mentioned this issue Feb 27, 2020
6 tasks
TheAngryByrd pushed a commit that referenced this issue Feb 27, 2020
Porting the code from https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/ to fix opening a browser in dotnetcore on windows
TheAngryByrd pushed a commit that referenced this issue Mar 8, 2020
Porting the code from https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/ to fix opening a browser in dotnetcore on windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants