diff --git a/src/Microsoft.DotNet.Cli.Utils/RuntimeConfig.cs b/src/Microsoft.DotNet.Cli.Utils/RuntimeConfig.cs index 5b0c8fcc5..61691e4a8 100644 --- a/src/Microsoft.DotNet.Cli.Utils/RuntimeConfig.cs +++ b/src/Microsoft.DotNet.Cli.Utils/RuntimeConfig.cs @@ -1,8 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. - + +using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using System.IO; +using System.IO; namespace Microsoft.DotNet.Cli.Utils { @@ -12,12 +13,16 @@ namespace Microsoft.DotNet.Cli.Utils public RuntimeConfigFramework Framework { get; } public RuntimeConfig(string runtimeConfigPath) - { - var runtimeConfigJson = OpenRuntimeConfig(runtimeConfigPath); - - Framework = ParseFramework(runtimeConfigJson); - - IsPortable = Framework != null; + { + JObject runtimeConfigJson; + using (var streamReader = new StreamReader(new FileStream(runtimeConfigPath, FileMode.Open))) + { + runtimeConfigJson = OpenRuntimeConfig(streamReader); + } + + Framework = ParseFramework(runtimeConfigJson); + + IsPortable = Framework != null; } public static bool IsApplicationPortable(string entryAssemblyPath) @@ -31,9 +36,11 @@ namespace Microsoft.DotNet.Cli.Utils return false; } - private JObject OpenRuntimeConfig(string runtimeConfigPath) - { - return JObject.Parse(File.ReadAllText(runtimeConfigPath)); + private JObject OpenRuntimeConfig(StreamReader streamReader) + { + var reader = new JsonTextReader(streamReader); + + return JObject.Load(reader); } private RuntimeConfigFramework ParseFramework(JObject runtimeConfigRoot) diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs b/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs index 70687e8d2..5ee3fd10c 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-package/AddPackageParser.cs @@ -3,10 +3,12 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using Microsoft.DotNet.Cli.CommandLine; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using LocalizableStrings = Microsoft.DotNet.Tools.Add.PackageReference.LocalizableStrings; @@ -52,7 +54,7 @@ namespace Microsoft.DotNet.Cli { var httpClient = new HttpClient(); - string result; + Stream result; try { @@ -60,14 +62,18 @@ namespace Microsoft.DotNet.Cli var response = httpClient.GetAsync($"https://api-v2v3search-0.nuget.org/query?q={match}&skip=0&take=100&prerelease=true", cancellation.Token) .Result; - result = response.Content.ReadAsStringAsync().Result; + result = response.Content.ReadAsStreamAsync().Result; } catch (Exception) { yield break; } - var json = JObject.Parse(result); + JObject json; + using (var reader = new JsonTextReader(new StreamReader(result))) + { + json = JObject.Load(reader); + } foreach (var id in json["data"]) {