diff --git a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/TestXmlReferenceResolver.cs b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/TestXmlReferenceResolver.cs index 6043abfd04..222de2ac4d 100644 --- a/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/TestXmlReferenceResolver.cs +++ b/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/TestXmlReferenceResolver.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; @@ -24,18 +25,28 @@ public override int GetHashCode() return RuntimeHelpers.GetHashCode(this); } - public override Stream? OpenRead(string resolvedPath) + public override Stream OpenRead(string resolvedPath) { + if (resolvedPath is null) + { + throw new ArgumentNullException(nameof(resolvedPath)); + } + if (!XmlReferences.TryGetValue(resolvedPath, out var content)) { - return null; + throw new IOException($"Unable to read XML file: {resolvedPath}"); } return new MemoryStream(Encoding.UTF8.GetBytes(content)); } - public override string ResolveReference(string path, string baseFilePath) + public override string? ResolveReference(string path, string baseFilePath) { + if (!XmlReferences.ContainsKey(path)) + { + return null; + } + return path; } }