1010using System . Threading . Tasks ;
1111using Microsoft . OpenApi . Interfaces ;
1212using Microsoft . OpenApi . Models ;
13- using Microsoft . VisualStudio . Threading ;
1413
1514namespace Microsoft . OpenApi . Reader
1615{
@@ -20,8 +19,6 @@ namespace Microsoft.OpenApi.Reader
2019 public static class OpenApiModelFactory
2120 {
2221 private static readonly HttpClient _httpClient = new ( ) ;
23- private static readonly JoinableTaskContext _joinableTaskContext = new ( ) ;
24- private static readonly JoinableTaskFactory _joinableTaskFactory = new ( _joinableTaskContext ) ;
2522
2623 static OpenApiModelFactory ( )
2724 {
@@ -36,7 +33,9 @@ static OpenApiModelFactory()
3633 /// <returns>An OpenAPI document instance.</returns>
3734 public static ReadResult Load ( string url , OpenApiReaderSettings settings = null )
3835 {
39- return _joinableTaskFactory . Run ( async ( ) => await LoadAsync ( url , settings ) ) ;
36+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
37+ return LoadAsync ( url , settings ) . GetAwaiter ( ) . GetResult ( ) ;
38+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
4039 }
4140
4241 /// <summary>
@@ -52,9 +51,10 @@ public static ReadResult Load(Stream stream,
5251 {
5352 settings ??= new OpenApiReaderSettings ( ) ;
5453
55- // Run the async method synchronously using JoinableTaskFactory
56- var result = _joinableTaskFactory . Run ( async ( ) => await LoadAsync ( stream , format , settings ) ) ;
57-
54+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
55+ var result = LoadAsync ( stream , format , settings ) . GetAwaiter ( ) . GetResult ( ) ;
56+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
57+
5858 if ( ! settings . LeaveStreamOpen )
5959 {
6060 stream . Dispose ( ) ;
@@ -74,8 +74,9 @@ public static ReadResult Load(TextReader input,
7474 string format ,
7575 OpenApiReaderSettings settings = null )
7676 {
77- // Run the async method synchronously using JoinableTaskFactory
78- var result = _joinableTaskFactory . Run ( async ( ) => await LoadAsync ( input , format , settings ) ) ;
77+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
78+ var result = LoadAsync ( input , format , settings ) . GetAwaiter ( ) . GetResult ( ) ;
79+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
7980 return result ;
8081 }
8182
@@ -153,7 +154,9 @@ public static ReadResult Parse(string input,
153154 settings ??= new OpenApiReaderSettings ( ) ;
154155 using var reader = new StringReader ( input ) ;
155156
156- return _joinableTaskFactory . Run ( async ( ) => await ParseAsync ( input , reader , format , settings ) ) ;
157+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
158+ return ParseAsync ( input , reader , format , settings ) . GetAwaiter ( ) . GetResult ( ) ;
159+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
157160 }
158161
159162 /// <summary>
@@ -208,7 +211,9 @@ public static T Load<T>(string url, OpenApiSpecVersion version, out OpenApiDiagn
208211 var format = GetFormat ( url ) ;
209212 settings ??= new OpenApiReaderSettings ( ) ;
210213
211- var stream = _joinableTaskFactory . Run ( async ( ) => await GetStreamAsync ( url ) ) ;
214+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
215+ var stream = GetStreamAsync ( url ) . GetAwaiter ( ) . GetResult ( ) ;
216+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
212217
213218 return Load < T > ( stream , version , format , out diagnostic , settings ) ;
214219 }
@@ -253,7 +258,10 @@ private static string GetContentType(string url)
253258 {
254259 if ( ! string . IsNullOrEmpty ( url ) )
255260 {
256- var response = _joinableTaskFactory . Run ( async ( ) => await _httpClient . GetAsync ( url ) ) ;
261+ #pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
262+ var response = _httpClient . GetAsync ( url ) . GetAwaiter ( ) . GetResult ( ) ;
263+ #pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
264+
257265 var mediaType = response . Content . Headers . ContentType . MediaType ;
258266 return mediaType . Split ( ";" . ToCharArray ( ) , StringSplitOptions . RemoveEmptyEntries ) . First ( ) ;
259267 }
0 commit comments