@@ -92,7 +92,10 @@ module internal RoslynHelpers =
9292member __.Proceed = not isStopped
9393member __.Stop () = isStopped<- true
9494
95- // This is like Async.StartAsTask, but if cancellation occurs we explicitly associate the cancellation with cancellationToken
95+ // This is like Async.StartAsTask, but
96+ // 1. if cancellation occurs we explicitly associate the cancellation with cancellationToken
97+ // 2. if exception occurs then set result to Unchecked.defaultof<_>, i.e. swallow exceptions
98+ // and hope that Roslyn copes with the null
9699let StartAsyncAsTask ( cancellationToken : CancellationToken ) computation =
97100let tcs = new TaskCompletionSource<_>( TaskCreationOptions.None)
98101let barrier = VolatileBarrier()
@@ -102,10 +105,24 @@ module internal RoslynHelpers =
102105 Async.StartWithContinuations(
103106async { do ! Async.SwitchToThreadPool()
104107return ! computation},
105- continuation=( fun result -> disposeReg(); tcs.TrySetResult( result) |> ignore),
106- exceptionContinuation=( function :? OperationCanceledException-> disposeReg(); tcs.TrySetCanceled( cancellationToken) |> ignore
107- | exn-> disposeReg(); tcs.TrySetException( exn) |> ignore),
108- cancellationContinuation=( fun _oce -> disposeReg(); tcs.TrySetCanceled( cancellationToken) |> ignore),
108+ continuation=( fun result ->
109+ disposeReg()
110+ tcs.TrySetResult( result) |> ignore
111+ ),
112+ exceptionContinuation=( fun exn ->
113+ disposeReg()
114+ match exnwith
115+ | :? OperationCanceledException->
116+ tcs.TrySetCanceled( cancellationToken) |> ignore
117+ | exn->
118+ System.Diagnostics.Trace.WriteLine( " Visual F# Tools: exception swallowed and not passed to Roslyn: {0}" , exn.Message)
119+ let res = Unchecked.defaultof<_>
120+ tcs.TrySetResult( res) |> ignore
121+ ),
122+ cancellationContinuation=( fun _oce ->
123+ disposeReg()
124+ tcs.TrySetCanceled( cancellationToken) |> ignore
125+ ),
109126 cancellationToken= cancellationToken)
110127 task
111128