diff --git a/eng/Directory.Packages.props b/eng/Directory.Packages.props index 7b2982ef1f035..43df945a6417a 100644 --- a/eng/Directory.Packages.props +++ b/eng/Directory.Packages.props @@ -255,7 +255,6 @@ - diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index 61e02f314754e..1cef8beaea68f 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -26,7 +26,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Emit; using Microsoft.CodeAnalysis.PooledObjects; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; using Microsoft.DiaSymReader; @@ -4339,7 +4338,7 @@ public void AppConfigBasic() "); - var silverlight = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).Path; + var silverlight = Temp.CreateFile().WriteAllBytes(Silverlight.System).Path; var net4_0dll = Temp.CreateFile().WriteAllBytes(Net461.Resources.System).Path; // Test linking two appconfig dlls with simple src diff --git a/src/Compilers/CSharp/Test/CommandLine/TouchedFileLoggingTests.cs b/src/Compilers/CSharp/Test/CommandLine/TouchedFileLoggingTests.cs index 78f7c4c5141f9..0a1b0c7c3b4fc 100644 --- a/src/Compilers/CSharp/Test/CommandLine/TouchedFileLoggingTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/TouchedFileLoggingTests.cs @@ -12,7 +12,6 @@ using System.Runtime.InteropServices; using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -77,7 +76,7 @@ public void AppConfigCsc() ").Path; - var silverlight = Temp.CreateFile().WriteAllBytes(ProprietaryTestResources.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).Path; + var silverlight = Temp.CreateFile().WriteAllBytes(Silverlight.System).Path; var net4_0dll = Temp.CreateFile().WriteAllBytes(Net461.Resources.System).Path; var outWriter = new StringWriter(CultureInfo.InvariantCulture); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs index cdf16455ae302..3ae7ccf2a7ec9 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTests.cs @@ -8,11 +8,11 @@ using System.IO; using System.Linq; using System.Threading; +using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis.CSharp.Emit; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Emit; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; @@ -473,7 +473,8 @@ public static void Main(string[] args) } }"; var tree = Parse(source); - var compilation = CreateEmptyCompilation(tree, new[] { MscorlibRefSilverlight }, TestOptions.ReleaseExe, assemblyName: "Test"); + var compilation = CreateEmptyCompilation(tree, [Net461.References.mscorlib], TestOptions.ReleaseExe, assemblyName: "Test"); + compilation.MakeMemberMissing(SpecialMember.System_Array__LongLength); CompileAndVerify(compilation, expectedOutput: "k"); } @@ -15130,7 +15131,7 @@ static void Main() } }"; - var testReference = AssemblyMetadata.CreateFromImage(ProprietaryTestResources.Repros.BadDefaultParameterValue).GetReference(); + var testReference = AssemblyMetadata.CreateFromImage(TestResources.SymbolsTests.Metadata.BadDefaultParameterValue).GetReference(); var compilation = CompileAndVerify(source, references: new[] { testReference }); compilation.VerifyIL("Program.Main", @" { diff --git a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs index ea003bba0b2f6..26e0d88f23509 100644 --- a/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/CodeGen/CodeGenCallTests.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Emit; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Xunit; diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index fd120694a384c..6ac8cbcb83698 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -6,6 +6,7 @@ using System.Collections.Immutable; using System.Linq; +using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; @@ -2119,7 +2120,7 @@ void Test(string s) } "; - var comp = CreateEmptyCompilation(source, new[] { MscorlibRefPortable }); + var comp = CreateEmptyCompilation(source, [SystemRuntimePP7Ref]); comp.VerifyDiagnostics(); var tree = comp.SyntaxTrees.Single(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs index 6bac9eb55fba2..1e55230cdfaa5 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs @@ -414,7 +414,8 @@ public static void Goo(Func func) var comp1 = CreateCompilation( Parse(text1), - new[] { TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true) }, + targetFramework: TargetFramework.NetFramework, + references: [TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true)], options: TestOptions.ReleaseDll); var text2 = @" @@ -429,22 +430,24 @@ public static void Main() var comp2 = CreateCompilation( Parse(text2), - new MetadataReference[] - { + targetFramework: TargetFramework.NetFramework, + references: + [ new CSharpCompilationReference(comp1), - TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true) - }, + TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true) + ], options: TestOptions.ReleaseExe); CompileAndVerify(comp2, expectedOutput: "Y").Diagnostics.Verify(); var comp3 = CreateCompilation( Parse(text2), - new MetadataReference[] - { + targetFramework: TargetFramework.NetFramework, + references: + [ comp1.EmitToImageReference(), - TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(true) - }, + TestReferences.SymbolsTests.NoPia.StdOleNetFramework.WithEmbedInteropTypes(true) + ], options: TestOptions.ReleaseExe); CompileAndVerify(comp3, expectedOutput: "Y").Diagnostics.Verify(); diff --git a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdDumpTest.cs b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdDumpTest.cs index 7e99956bcbe25..ad21fc4b06a2b 100644 --- a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdDumpTest.cs +++ b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdDumpTest.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using Roslyn.Utilities; @@ -27,7 +26,7 @@ public class WinMdDumpTest : CSharpTestBase private readonly MetadataReference _windowsRef = MetadataReference.CreateFromImage(TestResources.WinRt.Windows.AsImmutableOrNull()); private readonly MetadataReference _systemRuntimeRef = MetadataReference.CreateFromImage(Net461.Resources.SystemRuntime.AsImmutableOrNull()); private readonly MetadataReference _systemObjectModelRef = MetadataReference.CreateFromImage(Net461.Resources.SystemObjectModel.AsImmutableOrNull()); - private readonly MetadataReference _windowsRuntimeUIXamlRef = MetadataReference.CreateFromImage(ProprietaryTestResources.v4_0_30319_17929.System_Runtime_WindowsRuntime_UI_Xaml.AsImmutableOrNull()); + private readonly MetadataReference _windowsRuntimeUIXamlRef = MetadataReference.CreateFromImage(TestResources.NetFX.WinRt.SystemRuntimeWindowsRuntimeUIXaml.AsImmutableOrNull()); private readonly MetadataReference _interopServicesWindowsRuntimeRef = MetadataReference.CreateFromImage(Net461.Resources.SystemRuntimeInteropServicesWindowsRuntime.AsImmutableOrNull()); private void AppendMembers(StringBuilder result, NamespaceOrTypeSymbol container, string indent) diff --git a/src/Compilers/Core/CodeAnalysisTest/CryptoBlobParserTests.cs b/src/Compilers/Core/CodeAnalysisTest/CryptoBlobParserTests.cs index c3ef283b036f0..f0f8009d50a8d 100644 --- a/src/Compilers/Core/CodeAnalysisTest/CryptoBlobParserTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/CryptoBlobParserTests.cs @@ -170,24 +170,10 @@ public void TryGetPublicKeyFailsForInvalidKeyBlobs() "0602000000240000DEADBEEF" + new string('0', 136 * 2), // public key blob without magic public key }; - Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[0]), out _, out _)); - Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[1]), out _, out _)); - Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[2]), out _, out _)); - Assert.False(CryptoBlobParser.TryParseKey(HexToBin(invalidKeyBlobs[3]), out _, out _)); - } - - private static ImmutableArray HexToBin(string input) - { - Assert.True(input != null && (input.Length & 1) == 0, "invalid input string."); - - var result = new byte[input.Length >> 1]; - - for (var i = 0; i < result.Length; i++) - { - result[i] = byte.Parse(input.Substring(i << 1, 2), NumberStyles.HexNumber); - } - - return ImmutableArray.Create(result); + Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[0].AsSpan()), out _, out _)); + Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[1].AsSpan()), out _, out _)); + Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[2].AsSpan()), out _, out _)); + Assert.False(CryptoBlobParser.TryParseKey(TestHelpers.HexToByte(invalidKeyBlobs[3].AsSpan()), out _, out _)); } } } diff --git a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj index 6103306da16bd..730c518eee96b 100644 --- a/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj +++ b/src/Compilers/Test/Core/Microsoft.CodeAnalysis.Test.Utilities.csproj @@ -91,7 +91,6 @@ - diff --git a/src/Compilers/Test/Core/Mocks/Silverlight.cs b/src/Compilers/Test/Core/Mocks/Silverlight.cs new file mode 100644 index 0000000000000..9bfe8bc8ff200 --- /dev/null +++ b/src/Compilers/Test/Core/Mocks/Silverlight.cs @@ -0,0 +1,105 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Emit; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.Text; + +namespace Roslyn.Test.Utilities; + +/// +/// The assemblies produced here are designed to mimic the public key token structure of +/// silverlight references. This often presents challenges to the compiler because it has +/// to know that two mscorlib with different public key tokens need to be treated as the +/// identicial. The assemblies produced here have the same identity of those that come +/// from silverlight but without necessarily the same type contents. +/// +public static class Silverlight +{ + private static readonly Lazy<(byte[], byte[])> s_tuple = new Lazy<(byte[], byte[])>( + () => BuildImages(), + LazyThreadSafetyMode.PublicationOnly); + + public static byte[] Mscorlib => s_tuple.Value.Item1; + + public static byte[] System => s_tuple.Value.Item2; + + private static (byte[], byte[]) BuildImages() + { + const string corlibExtraCode = """ + using System; + using System.Reflection; + + namespace System.Reflection; + + [AttributeUsage(AttributeTargets.Assembly, Inherited = false)] + public sealed class AssemblyFileVersionAttribute : Attribute + { + public string Version { get; } + public AssemblyFileVersionAttribute(string version) + { + Version = version; + } + } + [AttributeUsage(AttributeTargets.Assembly, Inherited = false)] + public sealed class AssemblyVersionAttribute : Attribute + { + public string Version { get; } + public AssemblyVersionAttribute(string version) + { + Version = version; + } + } + """; + + const string assemblyAttributes = """ + using System.Reflection; + + [assembly: AssemblyFileVersion("5.0.5.0")] + [assembly: AssemblyVersion("5.0.5.0")] + """; + + var publicKeyText = "" + + "00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f" + + "383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148" + + "e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e" + + "5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab"; + var publicKey = TestHelpers.HexToByte(publicKeyText.AsSpan()); + var publicKeyToken = AssemblyIdentity.CalculatePublicKeyToken(publicKey); + Debug.Assert("7C-EC-85-D7-BE-A7-79-8E" == BitConverter.ToString(publicKeyToken.ToArray())); + + var options = new CSharpCompilationOptions( + OutputKind.DynamicallyLinkedLibrary, + cryptoPublicKey: publicKey, + optimizationLevel: OptimizationLevel.Release); + var mscorlibCompilation = CSharpCompilation.Create( + "mscorlib", + [ + CSharpSyntaxTree.ParseText(SourceText.From(TestResources.NetFX.Minimal.mincorlib_cs)), + CSharpSyntaxTree.ParseText(SourceText.From(corlibExtraCode)), + CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes)), + ], + options: options); + + var mscorlib = mscorlibCompilation.EmitToStream(EmitOptions.Default.WithRuntimeMetadataVersion("v4.0.30319")); + + var systemCompilation = CSharpCompilation.Create( + "System", + syntaxTrees: [CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes))], + references: [mscorlibCompilation.EmitToImageReference()], + options: options); + + var system = systemCompilation.EmitToStream(); + return (mscorlib.ToArray(), system.ToArray()); + } +} diff --git a/src/Compilers/Test/Core/Mocks/StdOle.cs b/src/Compilers/Test/Core/Mocks/StdOle.cs new file mode 100644 index 0000000000000..efad464a13c9b --- /dev/null +++ b/src/Compilers/Test/Core/Mocks/StdOle.cs @@ -0,0 +1,83 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.Text; + +namespace Roslyn.Test.Utilities; + +/// +/// This type produces stdole.dll that mimic the version used in the original Roslyn +/// interop tests. +/// +public static class StdOle +{ + public static PortableExecutableReference Build(IEnumerable references) + { + const string assemblyAttributes = """ + using System.Reflection; + using System.Runtime.InteropServices; + + [assembly: ImportedFromTypeLib("stdole")] + [assembly: Guid("00020430-0000-0000-c000-000000000046")] + [assembly: PrimaryInteropAssembly(2, 0)] + [assembly: AssemblyVersion("7.0.3300.0")] + + """; + + const string code = """ + using System.Runtime.InteropServices; + namespace stdole; + + public struct GUID + { + public uint Data1; + public ushort Data2; + public ushort Data3; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] + public byte[] Data4; + } + + [ComImport] + [Guid("00020400-0000-0000-C000-000000000046")] + [TypeLibType(512)] + public interface IDispatch + { + } + """; + + var publicKeyText = "" + + "002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e8" + + "4aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980" + + "957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1" + + "dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293"; + var publicKey = TestHelpers.HexToByte(publicKeyText.AsSpan()); + var publicKeyToken = AssemblyIdentity.CalculatePublicKeyToken(publicKey); + Debug.Assert("B0-3F-5F-7F-11-D5-0A-3A" == BitConverter.ToString(publicKeyToken.ToArray())); + + var options = new CSharpCompilationOptions( + OutputKind.DynamicallyLinkedLibrary, + cryptoPublicKey: publicKey, + optimizationLevel: OptimizationLevel.Release); + var compilation = CSharpCompilation.Create( + "stdole", + [ + CSharpSyntaxTree.ParseText(SourceText.From(code)), + CSharpSyntaxTree.ParseText(SourceText.From(assemblyAttributes)) + ], + references: references, + options); + + return compilation.EmitToPortableExecutableReference(); + } +} diff --git a/src/Compilers/Test/Core/Mocks/TestReferences.cs b/src/Compilers/Test/Core/Mocks/TestReferences.cs index 35b42d3633597..c338990d43864 100644 --- a/src/Compilers/Test/Core/Mocks/TestReferences.cs +++ b/src/Compilers/Test/Core/Mocks/TestReferences.cs @@ -7,9 +7,10 @@ using System; using System.IO; using System.Threading; +using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Roslyn.Test.Utilities; +using Xunit; public static class TestReferences { @@ -98,7 +99,7 @@ public static class ValueTuple public static class silverlight_v5_0_5_0 { private static readonly Lazy s_system = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.silverlight_v5_0_5_0.System_v5_0_5_0_silverlight).GetReference(display: "System.v5.0.5.0_silverlight.dll"), + () => AssemblyMetadata.CreateFromImage(Silverlight.System).GetReference(display: "System.v5.0.5.0_silverlight.dll"), LazyThreadSafetyMode.PublicationOnly); public static PortableExecutableReference System => s_system.Value; } @@ -688,10 +689,13 @@ public static class MultiTargeting public static class NoPia { - private static readonly Lazy s_stdOle = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.ProprietaryPias.stdole).GetReference(display: "stdole.dll"), - LazyThreadSafetyMode.PublicationOnly); - public static PortableExecutableReference StdOle => s_stdOle.Value; + private static readonly Lazy s_stdOleNetFramework = new Lazy( + () => StdOle.Build(NetFramework.References), LazyThreadSafetyMode.PublicationOnly); + public static PortableExecutableReference StdOleNetFramework => s_stdOleNetFramework.Value; + + private static readonly Lazy s_stdOleNet40 = new Lazy( + () => StdOle.Build(Net40.References.All), LazyThreadSafetyMode.PublicationOnly); + public static PortableExecutableReference StdOleNet40 => s_stdOleNet40.Value; private static readonly Lazy s_pia1 = new Lazy( () => AssemblyMetadata.CreateFromImage(TestResources.SymbolsTests.NoPia.Pia1).GetReference(display: "Pia1.dll"), diff --git a/src/Compilers/Test/Core/Platform/Desktop/TestHelpers.cs b/src/Compilers/Test/Core/Platform/Desktop/TestHelpers.cs index c00cc71683579..a58904aacffaa 100644 --- a/src/Compilers/Test/Core/Platform/Desktop/TestHelpers.cs +++ b/src/Compilers/Test/Core/Platform/Desktop/TestHelpers.cs @@ -13,7 +13,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; using Microsoft.Win32; diff --git a/src/Compilers/Test/Core/TestBase.cs b/src/Compilers/Test/Core/TestBase.cs index 4c52c0168b1f2..0930775cc7469 100644 --- a/src/Compilers/Test/Core/TestBase.cs +++ b/src/Compilers/Test/Core/TestBase.cs @@ -14,7 +14,6 @@ using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.VisualBasic; using static TestReferences.NetFx; -using Microsoft.CodeAnalysis.Test.Resources.Proprietary; using Basic.Reference.Assemblies; using Roslyn.Utilities; using System.Globalization; @@ -103,7 +102,7 @@ public virtual void Dispose() var winmd = AssemblyMetadata.CreateFromImage(TestResources.WinRt.Windows).GetReference(display: "Windows"); var windowsruntime = - AssemblyMetadata.CreateFromImage(ProprietaryTestResources.v4_0_30319_17929.System_Runtime_WindowsRuntime).GetReference(display: "System.Runtime.WindowsRuntime.dll"); + AssemblyMetadata.CreateFromImage(TestResources.NetFX.WinRt.SystemRuntimeWindowsRuntime).GetReference(display: "System.Runtime.WindowsRuntime.dll"); var runtime = AssemblyMetadata.CreateFromImage(Net461.Resources.SystemRuntime).GetReference(display: "System.Runtime.dll"); @@ -111,7 +110,7 @@ public virtual void Dispose() var objectModel = AssemblyMetadata.CreateFromImage(Net461.Resources.SystemObjectModel).GetReference(display: "System.ObjectModel.dll"); - var uixaml = AssemblyMetadata.CreateFromImage(ProprietaryTestResources.v4_0_30319_17929.System_Runtime_WindowsRuntime_UI_Xaml). + var uixaml = AssemblyMetadata.CreateFromImage(TestResources.NetFX.WinRt.SystemRuntimeWindowsRuntimeUIXaml). GetReference(display: "System.Runtime.WindowsRuntime.UI.Xaml.dll"); var interop = AssemblyMetadata.CreateFromImage(Net461.Resources.SystemRuntimeInteropServicesWindowsRuntime). @@ -186,11 +185,6 @@ public virtual void Dispose() LazyThreadSafetyMode.PublicationOnly); public static MetadataReference MscorlibRef => s_mscorlibRef.Value; - private static readonly Lazy s_mscorlibRefPortable = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.v4_0_30319.mscorlib_portable).GetReference(display: "mscorlib.v4_0_30319.portable.dll"), - LazyThreadSafetyMode.PublicationOnly); - public static MetadataReference MscorlibRefPortable => s_mscorlibRefPortable.Value; - private static readonly Lazy s_aacorlibRef = new Lazy( () => { @@ -223,14 +217,6 @@ public virtual void Dispose() LazyThreadSafetyMode.PublicationOnly); public static MetadataReference MscorlibRef_v46 => s_mscorlibRef_v46.Value; - /// - /// Reference to an mscorlib silverlight assembly in which the System.Array does not contain the special member LongLength. - /// - private static readonly Lazy s_mscorlibRef_silverlight = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.silverlight_v5_0_5_0.mscorlib_v5_0_5_0_silverlight).GetReference(display: "mscorlib.v5.0.5.0_silverlight.dll"), - LazyThreadSafetyMode.PublicationOnly); - public static MetadataReference MscorlibRefSilverlight => s_mscorlibRef_silverlight.Value; - public static MetadataReference MinCorlibRef => TestReferences.NetFx.Minimal.mincorlib; public static MetadataReference MinAsyncCorlibRef => TestReferences.NetFx.Minimal.minasynccorlib; @@ -318,12 +304,12 @@ public virtual void Dispose() public static MetadataReference SystemThreadingTaskFacadeRef => s_systemThreadingTasksFacadeRef.Value; private static readonly Lazy s_mscorlibPP7Ref = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.ReferenceAssemblies_PortableProfile7.mscorlib).GetReference(display: "mscorlib.dll"), + () => AssemblyMetadata.CreateFromImage(TestResources.NetFX.PortableProfile7.Mscorlib).GetReference(display: "mscorlib.dll"), LazyThreadSafetyMode.PublicationOnly); public static MetadataReference MscorlibPP7Ref => s_mscorlibPP7Ref.Value; private static readonly Lazy s_systemRuntimePP7Ref = new Lazy( - () => AssemblyMetadata.CreateFromImage(ProprietaryTestResources.ReferenceAssemblies_PortableProfile7.System_Runtime).GetReference(display: "System.Runtime.dll"), + () => AssemblyMetadata.CreateFromImage(TestResources.NetFX.PortableProfile7.SystemRuntime).GetReference(display: "System.Runtime.dll"), LazyThreadSafetyMode.PublicationOnly); public static MetadataReference SystemRuntimePP7Ref => s_systemRuntimePP7Ref.Value; diff --git a/src/Compilers/Test/Core/TestHelpers.cs b/src/Compilers/Test/Core/TestHelpers.cs index e0cd28c75ffc4..05f8777281074 100644 --- a/src/Compilers/Test/Core/TestHelpers.cs +++ b/src/Compilers/Test/Core/TestHelpers.cs @@ -11,6 +11,7 @@ using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Xml.Linq; using Microsoft.CodeAnalysis; @@ -146,5 +147,30 @@ public static string NormalizeNewLines(XCData data) return data.Value; } + + public static ImmutableArray HexToByte(ReadOnlySpan input) + { + if (input.Length % 2 != 0) + { + throw new ArgumentException("Length of the input string must be even", nameof(input)); + } + + var bytes = new byte[input.Length >> 1]; + for (var i = 0; i < bytes.Length; i++) + { + bytes[i] = parseByte(input.Slice(i << 1, 2), NumberStyles.HexNumber); + } + + return ImmutableCollectionsMarshal.AsImmutableArray(bytes); + + byte parseByte(ReadOnlySpan input, NumberStyles numberStyle) + { +#if NET + return byte.Parse(input, numberStyle); +#else + return byte.Parse(input.ToString(), numberStyle); +#endif + } + } } } diff --git a/src/Compilers/Test/Resources/Core/Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj b/src/Compilers/Test/Resources/Core/Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj index 9b0bcffc30be4..2e52cad71d476 100644 --- a/src/Compilers/Test/Resources/Core/Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj +++ b/src/Compilers/Test/Resources/Core/Microsoft.CodeAnalysis.Compiler.Test.Resources.csproj @@ -15,8 +15,7 @@ - - + @@ -85,11 +84,16 @@ + + + + + @@ -189,6 +193,7 @@ + @@ -370,13 +375,9 @@ - - - - @@ -384,8 +385,6 @@ - - diff --git a/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/System.Runtime.dll b/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/System.Runtime.dll new file mode 100644 index 0000000000000..0afd7a96a6308 Binary files /dev/null and b/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/System.Runtime.dll differ diff --git a/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/mscorlib.dll b/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/mscorlib.dll new file mode 100644 index 0000000000000..ce2519b1887fa Binary files /dev/null and b/src/Compilers/Test/Resources/Core/NetFX/PortableProfile7/mscorlib.dll differ diff --git a/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.UI.Xaml.dll b/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.UI.Xaml.dll new file mode 100644 index 0000000000000..e4bbbb5376e8f Binary files /dev/null and b/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.UI.Xaml.dll differ diff --git a/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.dll b/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.dll new file mode 100644 index 0000000000000..dbd3e5ea114bc Binary files /dev/null and b/src/Compilers/Test/Resources/Core/NetFX/WinRt/System.Runtime.WindowsRuntime.dll differ diff --git a/src/Compilers/Test/Resources/Core/SymbolsTests/Metadata/BadDefaultParameterValue.dll b/src/Compilers/Test/Resources/Core/SymbolsTests/Metadata/BadDefaultParameterValue.dll new file mode 100644 index 0000000000000..38a013b1a207c Binary files /dev/null and b/src/Compilers/Test/Resources/Core/SymbolsTests/Metadata/BadDefaultParameterValue.dll differ diff --git a/src/Compilers/Test/Resources/Core/TestResources.cs b/src/Compilers/Test/Resources/Core/TestResources.cs index 5a7f48629dcf9..a7fed061b198a 100644 --- a/src/Compilers/Test/Resources/Core/TestResources.cs +++ b/src/Compilers/Test/Resources/Core/TestResources.cs @@ -4,6 +4,8 @@ #nullable disable +using System; + namespace TestResources { public static class DiagnosticTests @@ -170,6 +172,9 @@ public static class Minimal private static byte[] s_mincorlib; public static byte[] mincorlib => ResourceLoader.GetOrCreateResource(ref s_mincorlib, "NetFX.Minimal.mincorlib.dll"); + private static string s_mincorlib_cs; + public static string mincorlib_cs => ResourceLoader.GetOrCreateResource(ref s_mincorlib_cs, "NetFX.Minimal.mincorlib.cs"); + private static byte[] s_minasync; public static byte[] minasync => ResourceLoader.GetOrCreateResource(ref s_minasync, "NetFX.Minimal.minasync.dll"); @@ -177,6 +182,24 @@ public static class Minimal public static byte[] minasynccorlib => ResourceLoader.GetOrCreateResource(ref s_minasynccorlib, "NetFX.Minimal.minasynccorlib.dll"); } + public static class PortableProfile7 + { + private static byte[] s_mscorlib; + public static byte[] Mscorlib => ResourceLoader.GetOrCreateResource(ref s_mscorlib, "NetFX.PortableProfile7.mscorlib.dll"); + + private static byte[] s_systemRuntime; + public static byte[] SystemRuntime => ResourceLoader.GetOrCreateResource(ref s_systemRuntime, "NetFX.PortableProfile7.System.Runtime.dll"); + } + + public static class WinRt + { + public static byte[] s_systemRuntimeWindowsRuntime; + public static byte[] SystemRuntimeWindowsRuntime => ResourceLoader.GetOrCreateResource(ref s_systemRuntimeWindowsRuntime, "NetFX.WinRt.System.Runtime.WindowsRuntime.dll"); + + public static byte[] s_systemRuntimeWindowsRuntimeUIXaml; + public static byte[] SystemRuntimeWindowsRuntimeUIXaml => ResourceLoader.GetOrCreateResource(ref s_systemRuntimeWindowsRuntimeUIXaml, "NetFX.WinRt.System.Runtime.WindowsRuntime.UI.Xaml.dll"); + } + public static class ValueTuple { private static byte[] s_tuplelib; @@ -489,6 +512,9 @@ public static class Metadata private static byte[] s_invalidPublicKey; public static byte[] InvalidPublicKey => ResourceLoader.GetOrCreateResource(ref s_invalidPublicKey, "SymbolsTests.Metadata.InvalidPublicKey.dll"); + private static byte[] s_badDefaultParameterValue; + public static byte[] BadDefaultParameterValue => ResourceLoader.GetOrCreateResource(ref s_badDefaultParameterValue, "SymbolsTests.Metadata.BadDefaultParameterValue.dll"); + private static byte[] s_MDTestAttributeApplicationLib; public static byte[] MDTestAttributeApplicationLib => ResourceLoader.GetOrCreateResource(ref s_MDTestAttributeApplicationLib, "SymbolsTests.Metadata.MDTestAttributeApplicationLib.dll"); diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb index 9c611c473152c..5283e27fcd974 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTests.vb @@ -5,7 +5,6 @@ Imports System.Collections.Immutable Imports System.Reflection Imports Microsoft.CodeAnalysis -Imports Microsoft.CodeAnalysis.Test.Resources.Proprietary Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic Imports Microsoft.CodeAnalysis.VisualBasic.Symbols @@ -13655,7 +13654,7 @@ End Module - Dim testReference = AssemblyMetadata.CreateFromImage(ProprietaryTestResources.Repros.BadDefaultParameterValue).GetReference() + Dim testReference = AssemblyMetadata.CreateFromImage(TestResources.SymbolsTests.Metadata.BadDefaultParameterValue).GetReference() Dim compilation = CompileAndVerify(source, references:=New MetadataReference() {testReference}) compilation.VerifyIL("C.Main", -, {MscorlibRefPortable}) +, {SystemRuntimePP7Ref}) comp.VerifyDiagnostics() @@ -1188,7 +1188,7 @@ Public Class C End Sub End Class -, {MscorlibRefPortable}) +, {SystemRuntimePP7Ref}) comp.VerifyDiagnostics() diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb index 9248ac3e59f8c..83ac35b4e7814 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Retargeting/NoPia.vb @@ -1661,7 +1661,7 @@ public delegate Sub Y(addin As List(Of string)) Dim comp1 = CreateCompilationWithMscorlib40(source1, options:=TestOptions.ReleaseDll, - references:={TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(True)}) + references:={TestReferences.SymbolsTests.NoPia.StdOleNet40.WithEmbedInteropTypes(True)}) Dim source2 = @@ -1676,14 +1676,14 @@ End Module Dim comp2 = CreateCompilationWithMscorlib40AndVBRuntimeAndReferences(source2, {comp1.EmitToImageReference(), - TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(True)}, + TestReferences.SymbolsTests.NoPia.StdOleNet40.WithEmbedInteropTypes(True)}, TestOptions.ReleaseExe) CompileAndVerify(comp2, expectedOutput:="Y").Diagnostics.Verify() Dim comp3 = CreateCompilationWithMscorlib40AndVBRuntimeAndReferences(source2, {New VisualBasicCompilationReference(comp1), - TestReferences.SymbolsTests.NoPia.StdOle.WithEmbedInteropTypes(True)}, + TestReferences.SymbolsTests.NoPia.StdOleNet40.WithEmbedInteropTypes(True)}, TestOptions.ReleaseExe) CompileAndVerify(comp3, expectedOutput:="Y").Diagnostics.Verify() diff --git a/src/EditorFeatures/Test/SymbolFinder/DependentTypeFinderTests.cs b/src/EditorFeatures/Test/SymbolFinder/DependentTypeFinderTests.cs index c28bb4f6a5fb4..5b768839c6340 100644 --- a/src/EditorFeatures/Test/SymbolFinder/DependentTypeFinderTests.cs +++ b/src/EditorFeatures/Test/SymbolFinder/DependentTypeFinderTests.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using System.Xml.Linq; +using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis.Editor.UnitTests; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.Remote.Testing; @@ -57,7 +58,7 @@ namespace N { public abstract class BaseClass { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -68,7 +69,7 @@ namespace M { public class DerivedClass : BaseClass { } } -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -98,7 +99,7 @@ namespace N { public interface BaseInterface { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -109,7 +110,7 @@ namespace M { public interface DerivedInterface : BaseInterface { } } -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -145,7 +146,7 @@ namespace N { public abstract class BaseClass { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -160,7 +161,7 @@ namespace M public class DerivedClass : Alias2 { } } -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -190,7 +191,7 @@ namespace N { public abstract class BaseClass { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -231,7 +232,7 @@ Namespace N Public MustInherit Class BaseClass End Class End Namespace -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -243,7 +244,7 @@ Public Class DerivedClass Inherits BaseClass End Class End Namespace -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -273,7 +274,7 @@ namespace N { public abstract class BaseClass { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -285,7 +286,7 @@ Public Class DerivedClass Inherits BaseClass End Class End Namespace -", MscorlibRef, portableProject.Id); +", Net40.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -315,7 +316,7 @@ namespace N { public interface IBaseInterface { } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -326,7 +327,7 @@ namespace M { public class ImplementingClass : IBaseInterface { } } -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -355,7 +356,7 @@ Namespace N Public Interface IBaseInterface End Interface End Namespace -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -367,7 +368,7 @@ Public Class ImplementingClass Implements IBaseInterface End Class End Namespace -", MscorlibRef, portableProject.Id); +", Net461.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -396,7 +397,7 @@ Namespace N Public Interface IBaseInterface End Interface End Namespace -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject = GetPortableProject(solution); @@ -407,7 +408,7 @@ namespace M { public class ImplementingClass : IBaseInterface { } } -", MscorlibRef, portableProject.Id); +", Net40.References.mscorlib, portableProject.Id); // get symbols for types var portableCompilation = await GetPortableProject(solution).GetCompilationAsync(); @@ -431,7 +432,7 @@ public async Task DerivedMetadataClasses(TestHost host) var solution = workspace.CurrentSolution; // create a normal assembly with a type derived from the portable abstract base - solution = AddProjectWithMetadataReferences(solution, "NormalProject", LanguageNames.CSharp, @"", MscorlibRef); + solution = AddProjectWithMetadataReferences(solution, "NormalProject", LanguageNames.CSharp, @"", Net40.References.mscorlib); // get symbols for types var compilation = await GetNormalProject(solution).GetCompilationAsync(); @@ -476,7 +477,7 @@ interface IC3 : IB3 { } interface ID1 : IC1 { } interface IOther { } -", MscorlibRef); +", Net40.References.mscorlib); // get symbols for types var compilation = await GetNormalProject(solution).GetCompilationAsync(); @@ -528,7 +529,7 @@ class D1 : C1 { } class OtherClass { } struct OtherStruct { } -", MscorlibRef); +", Net40.References.mscorlib); // get symbols for types var compilation = await GetNormalProject(solution).GetCompilationAsync(); @@ -565,7 +566,7 @@ public async Task ImplementingTypesDoesProduceDelegates(TestHost host) // create a normal assembly with a type derived from the portable abstract base solution = AddProjectWithMetadataReferences(solution, "NormalProject", LanguageNames.CSharp, @" delegate void D(); -", MscorlibRef); +", Net40.References.mscorlib); // get symbols for types var compilation = await GetNormalProject(solution).GetCompilationAsync(); @@ -595,7 +596,7 @@ enum E { A, B, C, } -", MscorlibRef); +", Net40.References.mscorlib); // get symbols for types var compilation = await GetNormalProject(solution).GetCompilationAsync(); @@ -679,7 +680,7 @@ public abstract class T_BaseProject_DerivedClass2 : T_BaseProject_DerivedClass1 { } } -", MscorlibRef); +", Net40.References.mscorlib); var normalProject1 = solution.Projects.Single(); @@ -691,7 +692,7 @@ public class T_DependProject_Class : T_BaseProject_DerivedClass2 { } } -", MscorlibRef, normalProject1.Id); +", Net40.References.mscorlib, normalProject1.Id); normalProject1 = solution.GetProject(normalProject1.Id); var normalProject2 = solution.Projects.Single(p => p != normalProject1); @@ -734,7 +735,7 @@ public interface I void M(); } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject1 = solution.Projects.Single(p => p.Name == "PortableProject1"); @@ -747,7 +748,7 @@ public class C : I public void M() { } } } -", MscorlibRefPortable, portableProject1.Id); +", Net40.References.mscorlib, portableProject1.Id); // get symbols for types var compilation1 = await solution.Projects.Single(p => p.Name == "PortableProject1").GetCompilationAsync(); @@ -778,7 +779,7 @@ public interface I void M(); } } -", MscorlibRefPortable); +", Net40.References.mscorlib); var portableProject1 = GetPortableProject(solution); diff --git a/src/Workspaces/CoreTest/FindReferencesTests.cs b/src/Workspaces/CoreTest/FindReferencesTests.cs index 909a0db02fee3..45edebba88936 100644 --- a/src/Workspaces/CoreTest/FindReferencesTests.cs +++ b/src/Workspaces/CoreTest/FindReferencesTests.cs @@ -461,7 +461,7 @@ public class BaseClass public virtual void SomeMethod() { } } } -", MscorlibRefPortable); +", MscorlibPP7Ref); // create a normal assembly with a type derived from the portable base and overriding the method solution = AddProjectWithMetadataReferences(solution, "NormalProject", LanguageNames.CSharp, @" @@ -473,7 +473,7 @@ public class DerivedClass : BaseClass public override void SomeMethod() { } } } -", MscorlibRef, solution.Projects.Single(pid => pid.Name == "PortableProject").Id); +", Net40.References.mscorlib, solution.Projects.Single(pid => pid.Name == "PortableProject").Id); // get symbols for methods var portableCompilation = await solution.Projects.Single(p => p.Name == "PortableProject").GetCompilationAsync();