public AssemblyIdentityAndLocation(AssemblyIdentity identity, string location) { Debug.Assert(identity != null && location != null); this.Identity = identity; this.Location = location; }
internal string GetErrorMessageAndMissingAssemblyIdentities(DiagnosticBag diagnostics, DiagnosticFormatter formatter, CultureInfo preferredUICulture, AssemblyIdentity linqLibrary, out bool useReferencedModulesOnly, out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities) { var errors = diagnostics.AsEnumerable().Where(d => d.Severity == DiagnosticSeverity.Error); foreach (var error in errors) { missingAssemblyIdentities = this.GetMissingAssemblyIdentities(error, linqLibrary); if (!missingAssemblyIdentities.IsDefault) { break; } } if (missingAssemblyIdentities.IsDefault) { missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty; } useReferencedModulesOnly = errors.All(HasDuplicateTypesOrAssemblies); var firstError = errors.FirstOrDefault(); Debug.Assert(firstError != null); var simpleMessage = firstError as SimpleMessageDiagnostic; return (simpleMessage != null) ? simpleMessage.GetMessage() : formatter.Format(firstError, preferredUICulture ?? CultureInfo.CurrentUICulture); }
public AddMissingReferenceCodeAction(Project project, string title, ProjectReference projectReferenceToAdd, AssemblyIdentity missingAssemblyIdentity) { _project = project; Title = title; _projectReferenceToAdd = projectReferenceToAdd; _missingAssemblyIdentity = missingAssemblyIdentity; }
public void MultipleAssemblyArguments() { var identity1 = new AssemblyIdentity(GetUniqueName()); var identity2 = new AssemblyIdentity(GetUniqueName()); Assert.Equal(identity1, GetMissingAssemblyIdentity(ErrorCode.ERR_NoTypeDef, identity1, identity2)); Assert.Equal(identity2, GetMissingAssemblyIdentity(ErrorCode.ERR_NoTypeDef, identity2, identity1)); }
public void FusionAssemblyNameRoundTrip() { RoundTrip(new AssemblyName("foo")); RoundTrip(new AssemblyName { Name = "~!@#$%^&*()_+={}:\"<>?[];',./" }); RoundTrip(new AssemblyName("\\,")); RoundTrip(new AssemblyName("\\\"")); RoundTrip(new AssemblyIdentity("foo").ToAssemblyName()); // 0xffff version is not included in AssemblyName.FullName for some reason: var name = new AssemblyIdentity("foo", version: new Version(0xffff, 0xffff, 0xffff, 0xffff)).ToAssemblyName(); RoundTrip(name, testFullName: false); var obj = FusionAssemblyIdentity.ToAssemblyNameObject(name); var display = FusionAssemblyIdentity.GetDisplayName(obj, FusionAssemblyIdentity.ASM_DISPLAYF.FULL); Assert.Equal("foo, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=null", display); RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4)).ToAssemblyName()); RoundTrip(new AssemblyName("foo") { Version = new Version(1, 2, 3, 4) }); RoundTrip(new AssemblyIdentity("foo", cultureName: CultureInfo.CurrentCulture.Name).ToAssemblyName()); RoundTrip(new AssemblyIdentity("foo", cultureName: "").ToAssemblyName()); RoundTrip(new AssemblyName("foo") { CultureInfo = CultureInfo.InvariantCulture }); RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4), cultureName: "en-US").ToAssemblyName()); RoundTrip(new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }.AsImmutableOrNull()).ToAssemblyName()); RoundTrip(new AssemblyIdentity("foo", version: new Version(1, 2, 3, 4), cultureName: CultureInfo.CurrentCulture.Name, publicKeyOrToken: new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }.AsImmutableOrNull()).ToAssemblyName()); RoundTrip(new AssemblyIdentity("foo", isRetargetable: true).ToAssemblyName()); RoundTrip(new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime).ToAssemblyName()); }
/// <summary> /// Allocates a reference to a .NET assembly. /// </summary> /// <param name="host">Provides a standard abstraction over the applications that host components that provide or consume objects from the metadata model.</param> /// <param name="assemblyIdentity">The identity of the referenced assembly.</param> /// <param name="isRetargetable">True if the implementation of the referenced assembly used at runtime is not expected to match the version seen at compile time.</param> /// <param name="containsForeignTypes"> /// True if the referenced assembly contains types that describe objects that are neither COM objects nor objects that are managed by the CLR. /// Instances of such types are created and managed by another runtime and are accessed by CLR objects via some form of interoperation mechanism. /// </param> public AssemblyReference(IMetadataHost host, AssemblyIdentity assemblyIdentity, bool isRetargetable = false, bool containsForeignTypes = false) { this.host = host; this.assemblyIdentity = assemblyIdentity; this.isRetargetable = isRetargetable; this.containsForeignTypes = containsForeignTypes; }
public LoadedAssemblyInfo(Assembly assembly, AssemblyIdentity identity, string locationOpt) { Debug.Assert(assembly != null && identity != null); Assembly = assembly; Identity = identity; LocationOpt = locationOpt; }
public ExternAliasRecord(string alias, AssemblyIdentity targetIdentity) { Debug.Assert(alias != null); Debug.Assert(targetIdentity != null); Alias = alias; TargetAssembly = targetIdentity; }
public UnifiedAssembly(AssemblySymbol targetAssembly, AssemblyIdentity originalReference) { Debug.Assert(originalReference != null); Debug.Assert(targetAssembly != null); this.OriginalReference = originalReference; this.TargetAssembly = targetAssembly; }
public void Equality_InvariantCulture() { var neutral1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "NEUtral", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var neutral2 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), null, RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var neutral3 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "neutral", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var invariant = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); Assert.True(neutral1.Equals(invariant)); Assert.True(neutral2.Equals(invariant)); Assert.True(neutral3.Equals(invariant)); }
public MetadataAsSourceGeneratedFileInfo(string rootPath, Project sourceProject, INamedTypeSymbol topLevelNamedType) { this.SourceProjectId = sourceProject.Id; this.Workspace = sourceProject.Solution.Workspace; this.LanguageName = sourceProject.Language; this.References = sourceProject.MetadataReferences.ToImmutableArray(); this.AssemblyIdentity = topLevelNamedType.ContainingAssembly.Identity; var extension = sourceProject.Language == LanguageNames.CSharp ? ".cs" : ".vb"; var directoryName = Guid.NewGuid().ToString("N"); this.TemporaryFilePath = Path.Combine(rootPath, directoryName, topLevelNamedType.Name + extension); }
public MetadataDefinitionItem( ImmutableArray<string> tags, ImmutableArray<TaggedText> displayParts, bool displayIfNoReferences, Solution solution, ISymbol definition) : base(tags, displayParts, GetOriginationParts(definition), ImmutableArray<DocumentLocation>.Empty, displayIfNoReferences) { _workspace = solution.Workspace; _symbolKey = definition.GetSymbolKey(); _symbolAssemblyIdentity = definition.ContainingAssembly?.Identity; }
public void Equality() { var id1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false); var id11 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false); var id2 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var id22 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var id3 = new AssemblyIdentity("Foo!", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var id4 = new AssemblyIdentity("Foo", new Version(1, 0, 1, 0), "", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var id5 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "en-US", RoPublicKeyToken1, hasPublicKey: false, isRetargetable: false); var id6 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", default(ImmutableArray<byte>), hasPublicKey: false, isRetargetable: false); var id7 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKeyToken1, hasPublicKey: true, isRetargetable: false); var id8 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: true); var win1 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime); var win2 = new AssemblyIdentity("Bar", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime); var win3 = new AssemblyIdentity("Foo", new Version(1, 0, 0, 0), "", RoPublicKey1, hasPublicKey: true, isRetargetable: false, contentType: AssemblyContentType.WindowsRuntime); Assert.True(id1.Equals(id1)); Assert.True(id1.Equals(id2)); Assert.True(id2.Equals(id1)); Assert.True(id1.Equals(id11)); Assert.True(id11.Equals(id1)); Assert.True(id2.Equals(id22)); Assert.True(id22.Equals(id2)); Assert.False(id1.Equals(id3)); Assert.False(id1.Equals(id4)); Assert.False(id1.Equals(id5)); Assert.False(id1.Equals(id6)); Assert.False(id1.Equals(id7)); Assert.False(id1.Equals(id8)); Assert.Equal((object)id1, id1); Assert.NotNull(id1); Assert.False(id2.Equals((AssemblyIdentity)null)); Assert.Equal(id1.GetHashCode(), id2.GetHashCode()); Assert.False(win1.Equals(win2)); Assert.False(win1.Equals(id1)); Assert.True(win1.Equals(win3)); Assert.Equal(win1.GetHashCode(), win3.GetHashCode()); }
public static async Task<CodeAction> CreateAsync(Project project, AssemblyIdentity missingAssemblyIdentity, CancellationToken cancellationToken) { var dependencyGraph = project.Solution.GetProjectDependencyGraph(); // We want to find a project that generates this assembly, if one so exists. We therefore // search all projects that our project with an error depends on. We want to do this for // complicated and evil scenarios like this one: // // C -> B -> A // // A' // // Where, for some insane reason, A and A' are two projects that both emit an assembly // by the same name. So imagine we are using a type in B from C, and we are missing a // reference to A.dll. Both A and A' are candidates, but we know we can throw out A' // since whatever type from B we are using that's causing the error, we know that type // isn't referencing A'. Put another way: this code action adds a reference, but should // never change the transitive closure of project references that C has. // // Doing this filtering also means we get to check less projects (good), and ensures that // whatever project reference we end up adding won't add a circularity (also good.) foreach (var candidateProjectId in dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id)) { var candidateProject = project.Solution.GetProject(candidateProjectId); if (string.Equals(missingAssemblyIdentity.Name, candidateProject.AssemblyName, StringComparison.OrdinalIgnoreCase)) { // The name matches, so let's see if the full identities are equal. var compilation = await candidateProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false); if (missingAssemblyIdentity.Equals(compilation.Assembly.Identity)) { // It matches, so just add a reference to this return new AddMissingReferenceCodeAction(project, string.Format(FeaturesResources.Add_project_reference_to_0, candidateProject.Name), new ProjectReference(candidateProjectId), missingAssemblyIdentity); } } } // No matching project, so metadata reference var description = string.Format(FeaturesResources.Add_reference_to_0, missingAssemblyIdentity.GetDisplayName()); return new AddMissingReferenceCodeAction(project, description, null, missingAssemblyIdentity); }
public void ERR_NoTypeDef() { var libSource = @" public class Missing { } "; var source = @" public class C { public void M(Missing parameter) { } } "; var libRef = CreateCompilationWithMscorlib(libSource, assemblyName: "Lib").EmitToImageReference(); var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.DebugDll); var context = CreateMethodContextWithReferences(comp, "C.M", MscorlibRef); var expectedError = "error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'Lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'."; var expectedMissingAssemblyIdentity = new AssemblyIdentity("Lib"); ResultProperties resultProperties; string actualError; ImmutableArray<AssemblyIdentity> actualMissingAssemblyIdentities; context.CompileExpression( DefaultInspectionContext.Instance, "parameter", DkmEvaluationFlags.TreatAsExpression, DiagnosticFormatter.Instance, out resultProperties, out actualError, out actualMissingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData: null); Assert.Equal(expectedError, actualError); Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single()); }
public void MissingType() { var libSource = @" public class Missing { } "; var source = @" public class C { Missing field; public void M(Missing parameter) { Missing local; } } "; var libRef = CreateCompilationWithMscorlib(libSource, assemblyName: "Lib").EmitToImageReference(); var comp = CreateCompilationWithMscorlib(source, new[] { libRef }, TestOptions.DebugDll); byte[] exeBytes; byte[] pdbBytes; ImmutableArray<MetadataReference> unusedReferences; var result = comp.EmitAndGetReferences(out exeBytes, out pdbBytes, out unusedReferences); Assert.True(result); var runtime = CreateRuntimeInstance(GetUniqueName(), ImmutableArray.Create(MscorlibRef), exeBytes, new SymReader(pdbBytes)); var context = CreateMethodContext(runtime, "C.M"); var expectedError = "error CS0012: The type 'Missing' is defined in an assembly that is not referenced. You must add a reference to assembly 'Lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'."; var expectedMissingAssemblyIdentity = new AssemblyIdentity("Lib"); ResultProperties resultProperties; string actualError; ImmutableArray<AssemblyIdentity> actualMissingAssemblyIdentities; Action<string> verify = expr => { context.CompileExpression( expr, DkmEvaluationFlags.TreatAsExpression, NoAliases, DiagnosticFormatter.Instance, out resultProperties, out actualError, out actualMissingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData: null); Assert.Equal(expectedError, actualError); Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single()); }; verify("M(null)"); verify("field"); verify("field.Method"); verify("parameter"); verify("parameter.Method"); verify("local"); verify("local.Method"); // Note that even expressions that don't require the missing type will fail because // the method we synthesize refers to the original locals and parameters. verify("0"); }
private void TestParseDisplayName(string displayName, AssemblyIdentity expected, AssemblyIdentityParts expectedParts = 0) { TestParseDisplayName(displayName, expected, expectedParts, expected); }
internal AssemblyReference(AssemblyIdentity identity) { _identity = identity; }
public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity) { // look in the GAC: if (GacFileResolver != null && referenceIdentity.IsStrongName) { var path = GacFileResolver.Resolve(referenceIdentity.GetDisplayName()); if (path != null) { return(CreateResolvedMissingReference(path)); } } // look in the directory of the requesting definition: var definitionPath = (definition as PortableExecutableReference)?.FilePath; if (definitionPath != null) { var pathWithoutExtension = PathUtilities.CombinePathsUnchecked(PathUtilities.GetDirectoryName(definitionPath), referenceIdentity.Name); foreach (var extension in AssemblyExtensions) { var fullPath = pathWithoutExtension + extension; if (File.Exists(fullPath)) { return(CreateResolvedMissingReference(fullPath)); } } } return(null); }
internal override ImmutableArray<AssemblyIdentity> GetMissingAssemblyIdentities(Diagnostic diagnostic, AssemblyIdentity linqLibrary) { return GetMissingAssemblyIdentitiesHelper((ErrorCode)diagnostic.Code, diagnostic.Arguments, linqLibrary); }
public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity) { return(_resolvedAssembliesCache.GetOrAdd(referenceIdentity, id => _resolver.ResolveMissingAssembly(definition, id))); }
/// <summary> /// Resolves <see cref="System.Type"/> to a <see cref="TypeSymbol"/> available in this assembly /// its referenced assemblies. /// </summary> /// <param name="type">The type to resolve.</param> /// <param name="includeReferences">Use referenced assemblies for resolution.</param> /// <returns>The resolved symbol if successful or null on failure.</returns> internal TypeSymbol GetTypeByReflectionType(Type type, bool includeReferences) { System.Reflection.TypeInfo typeInfo = type.GetTypeInfo(); Debug.Assert(!typeInfo.IsByRef); // not supported (we don't accept open types as submission results nor host types): Debug.Assert(!typeInfo.ContainsGenericParameters); if (typeInfo.IsArray) { TypeSymbol symbol = GetTypeByReflectionType(typeInfo.GetElementType(), includeReferences); if ((object)symbol == null) { return(null); } int rank = typeInfo.GetArrayRank(); return(ArrayTypeSymbol.CreateCSharpArray(this, symbol, ImmutableArray <CustomModifier> .Empty, rank)); } else if (typeInfo.IsPointer) { TypeSymbol symbol = GetTypeByReflectionType(typeInfo.GetElementType(), includeReferences); if ((object)symbol == null) { return(null); } return(new PointerTypeSymbol(symbol)); } else if (typeInfo.DeclaringType != null) { Debug.Assert(!typeInfo.IsArray); // consolidated generic arguments (includes arguments of all declaring types): Type[] genericArguments = typeInfo.GenericTypeArguments; int typeArgumentIndex = 0; var currentTypeInfo = typeInfo.IsGenericType ? typeInfo.GetGenericTypeDefinition().GetTypeInfo() : typeInfo; var nestedTypes = ArrayBuilder <System.Reflection.TypeInfo> .GetInstance(); while (true) { Debug.Assert(currentTypeInfo.IsGenericTypeDefinition || !currentTypeInfo.IsGenericType); nestedTypes.Add(currentTypeInfo); if (currentTypeInfo.DeclaringType == null) { break; } currentTypeInfo = currentTypeInfo.DeclaringType.GetTypeInfo(); } int i = nestedTypes.Count - 1; var symbol = (NamedTypeSymbol)GetTypeByReflectionType(nestedTypes[i].AsType(), includeReferences); if ((object)symbol == null) { return(null); } while (--i >= 0) { int forcedArity = nestedTypes[i].GenericTypeParameters.Length - nestedTypes[i + 1].GenericTypeParameters.Length; MetadataTypeName mdName = MetadataTypeName.FromTypeName(nestedTypes[i].Name, forcedArity: forcedArity); symbol = symbol.LookupMetadataType(ref mdName); if ((object)symbol == null || symbol.IsErrorType()) { return(null); } symbol = ApplyGenericArguments(symbol, genericArguments, ref typeArgumentIndex, includeReferences); if ((object)symbol == null) { return(null); } } nestedTypes.Free(); Debug.Assert(typeArgumentIndex == genericArguments.Length); return(symbol); } else { AssemblyIdentity assemblyId = AssemblyIdentity.FromAssemblyDefinition(typeInfo.Assembly); MetadataTypeName mdName = MetadataTypeName.FromNamespaceAndTypeName( typeInfo.Namespace ?? string.Empty, typeInfo.Name, forcedArity: typeInfo.GenericTypeArguments.Length); NamedTypeSymbol symbol = GetTopLevelTypeByMetadataName(ref mdName, assemblyId, includeReferences, isWellKnownType: false, conflicts: out var _); if ((object)symbol == null || symbol.IsErrorType()) { return(null); } int typeArgumentIndex = 0; Type[] genericArguments = typeInfo.GenericTypeArguments; symbol = ApplyGenericArguments(symbol, genericArguments, ref typeArgumentIndex, includeReferences); Debug.Assert(typeArgumentIndex == genericArguments.Length); return(symbol); } }
public void MultiTargeting4() { var localC1_V1_Name = new AssemblyIdentity("c1", new Version("1.0.0.0")); var localC1_V1 = CreateCompilation(localC1_V1_Name, new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source1Module.netmodule @" public class C1<T> { public class C2<S> { public C1<T>.C2<S> Foo() { return null; } } } " }, new[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm1_V1 = localC1_V1.SourceAssembly(); var localC1_V2_Name = new AssemblyIdentity("c1", new Version("2.0.0.0")); var localC1_V2 = CreateCompilation(localC1_V2_Name, new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source1Module.netmodule @" public class C1<T> { public class C2<S> { public C1<T>.C2<S> Foo() { return null; } } } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm1_V2 = localC1_V2.SourceAssembly(); var localC4_V1_Name = new AssemblyIdentity("c4", new Version("1.0.0.0")); var localC4_V1 = CreateCompilation(localC4_V1_Name, new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source4Module.netmodule @" public class C4 { } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm4_V1 = localC4_V1.SourceAssembly(); var localC4_V2_Name = new AssemblyIdentity("c4", new Version("2.0.0.0")); var localC4_V2 = CreateCompilation(localC4_V2_Name, new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source4Module.netmodule @" public class C4 { } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm4_V2 = localC4_V2.SourceAssembly(); var c7 = CreateCompilation(new AssemblyIdentity("C7"), new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source7Module.netmodule @" public class C7 {} public class C8<T> { } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm7 = c7.SourceAssembly(); var c3 = CreateCompilation(new AssemblyIdentity("C3"), new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source3Module.netmodule @" public class C3 { public C1<C3>.C2<C4> Foo() { return null; } public static C6<C4> Bar() { return null; } public C8<C7> Foo1() { return null; } public void Foo2(ref C300[,] x1, out C4 x2, ref C7[] x3, C4 x4 = null) { x2 = null; } internal virtual TFoo3 Foo3<TFoo3>() where TFoo3: C4 { return null; } public C8<C4> Foo4() { return null; } public abstract class C301 : I1 { } internal class C302 { } } public class C6<T> where T: new () {} public class C300 {} public interface I1 {} namespace ns1 { namespace ns2 { public class C303 {} } public class C304 { public class C305 {} } } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(localC1_V1), new CSharpCompilationReference(localC4_V1), new CSharpCompilationReference(c7) }); var asm3 = c3.SourceAssembly(); var localC3Foo2 = asm3.GlobalNamespace.GetTypeMembers("C3"). Single().GetMembers("Foo2").OfType<MethodSymbol>().Single(); var c5 = CreateCompilation(new AssemblyIdentity("C5"), new string[] { // AssemblyPaths.SymbolsTests.MultiTargeting.Source5Module.netmodule @" public class C5 : ns1.C304.C305 {} " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(c3), new CSharpCompilationReference(localC1_V2), new CSharpCompilationReference(localC4_V2), new CSharpCompilationReference(c7) }); var asm5 = c5.SourceAssembly().BoundReferences(); Assert.NotSame(asm5[1], asm3); Assert.Same(((RetargetingAssemblySymbol)asm5[1]).UnderlyingAssembly, asm3); Assert.Same(asm5[2], asm1_V2); Assert.Same(asm5[3], asm4_V2); Assert.Same(asm5[4], asm7); var type3 = asm5[1].GlobalNamespace.GetTypeMembers("C3"). Single(); var type1 = asm1_V2.GlobalNamespace.GetTypeMembers("C1"). Single(); var type2 = type1.GetTypeMembers("C2"). Single(); var type4 = asm4_V2.GlobalNamespace.GetTypeMembers("C4"). Single(); var retval1 = (NamedTypeSymbol)type3.GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("C1<C3>.C2<C4>", retval1.ToTestDisplayString()); Assert.Same(retval1.OriginalDefinition, type2); var args1 = retval1.ContainingType.TypeArguments.Concat(retval1.TypeArguments); var params1 = retval1.ContainingType.TypeParameters.Concat(retval1.TypeParameters); Assert.Same(params1[0], type1.TypeParameters[0]); Assert.Same(params1[1].OriginalDefinition, type2.TypeParameters[0].OriginalDefinition); Assert.Same(args1[0], type3); Assert.Same(args1[0].ContainingAssembly, asm5[1]); Assert.Same(args1[1], type4); var retval2 = retval1.ContainingType; Assert.Equal("C1<C3>", retval2.ToTestDisplayString()); Assert.Same(retval2.OriginalDefinition, type1); var bar = type3.GetMembers("Bar").OfType<MethodSymbol>().Single(); var retval3 = (NamedTypeSymbol)bar.ReturnType; var type6 = asm5[1].GlobalNamespace.GetTypeMembers("C6"). Single(); Assert.Equal("C6<C4>", retval3.ToTestDisplayString()); Assert.Same(retval3.OriginalDefinition, type6); Assert.Same(retval3.ContainingAssembly, asm5[1]); var args3 = retval3.TypeArguments; var params3 = retval3.TypeParameters; Assert.Same(params3[0], type6.TypeParameters[0]); Assert.Same(params3[0].ContainingAssembly, asm5[1]); Assert.Same(args3[0], type4); var foo1 = type3.GetMembers("Foo1").OfType<MethodSymbol>().Single(); var retval4 = foo1.ReturnType; Assert.Equal("C8<C7>", retval4.ToTestDisplayString()); Assert.Same(retval4, asm3.GlobalNamespace.GetTypeMembers("C3"). Single(). GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType); var foo1Params = foo1.Parameters; Assert.Equal(0, foo1Params.Length); var foo2 = type3.GetMembers("Foo2").OfType<MethodSymbol>().Single(); Assert.NotEqual(localC3Foo2, foo2); Assert.Same(localC3Foo2, ((RetargetingMethodSymbol)foo2).UnderlyingMethod); Assert.Equal(1, ((RetargetingMethodSymbol)foo2).Locations.Length); var foo2Params = foo2.Parameters; Assert.Equal(4, foo2Params.Length); Assert.Same(localC3Foo2.Parameters[0], ((RetargetingParameterSymbol)foo2Params[0]).UnderlyingParameter); Assert.Same(localC3Foo2.Parameters[1], ((RetargetingParameterSymbol)foo2Params[1]).UnderlyingParameter); Assert.Same(localC3Foo2.Parameters[2], ((RetargetingParameterSymbol)foo2Params[2]).UnderlyingParameter); Assert.Same(localC3Foo2.Parameters[3], ((RetargetingParameterSymbol)foo2Params[3]).UnderlyingParameter); var x1 = foo2Params[0]; var x2 = foo2Params[1]; var x3 = foo2Params[2]; var x4 = foo2Params[3]; Assert.Equal("x1", x1.Name); Assert.NotEqual(localC3Foo2.Parameters[0].Type, x1.Type); Assert.Equal(localC3Foo2.Parameters[0].ToTestDisplayString(), x1.ToTestDisplayString()); Assert.Same(asm5[1], x1.ContainingAssembly); Assert.Same(foo2, x1.ContainingSymbol); Assert.False(x1.HasExplicitDefaultValue); Assert.False(x1.IsOptional); Assert.Equal(RefKind.Ref, x1.RefKind); Assert.Equal(2, ((ArrayTypeSymbol)x1.Type).Rank); Assert.Equal("x2", x2.Name); Assert.NotEqual(localC3Foo2.Parameters[1].Type, x2.Type); Assert.Equal(RefKind.Out, x2.RefKind); Assert.Equal("x3", x3.Name); Assert.Same(localC3Foo2.Parameters[2].Type, x3.Type); Assert.Equal("x4", x4.Name); Assert.True(x4.HasExplicitDefaultValue); Assert.True(x4.IsOptional); Assert.Equal("Foo2", foo2.Name); Assert.Equal(localC3Foo2.ToTestDisplayString(), foo2.ToTestDisplayString()); Assert.Same(asm5[1], foo2.ContainingAssembly); Assert.Same(type3, foo2.ContainingSymbol); Assert.Equal(Accessibility.Public, foo2.DeclaredAccessibility); Assert.False(foo2.HidesBaseMethodsByName); Assert.False(foo2.IsAbstract); Assert.False(foo2.IsExtern); Assert.False(foo2.IsGenericMethod); Assert.False(foo2.IsOverride); Assert.False(foo2.IsSealed); Assert.False(foo2.IsStatic); Assert.False(foo2.IsVararg); Assert.False(foo2.IsVirtual); Assert.True(foo2.ReturnsVoid); Assert.Equal(0, foo2.TypeParameters.Length); Assert.Equal(0, foo2.TypeArguments.Length); Assert.True(bar.IsStatic); Assert.False(bar.ReturnsVoid); var foo3 = type3.GetMembers("Foo3").OfType<MethodSymbol>().Single(); Assert.Equal(Accessibility.Internal, foo3.DeclaredAccessibility); Assert.True(foo3.IsGenericMethod); Assert.True(foo3.IsVirtual); var foo3TypeParams = foo3.TypeParameters; Assert.Equal(1, foo3TypeParams.Length); Assert.Equal(1, foo3.TypeArguments.Length); Assert.Same(foo3TypeParams[0], foo3.TypeArguments[0]); var typeC301 = type3.GetTypeMembers("C301").Single(); var typeC302 = type3.GetTypeMembers("C302").Single(); var typeC6 = asm5[1].GlobalNamespace.GetTypeMembers("C6").Single(); Assert.Equal(typeC301.ToTestDisplayString(), asm3.GlobalNamespace.GetTypeMembers("C3").Single(). GetTypeMembers("C301").Single().ToTestDisplayString()); Assert.Equal(typeC6.ToTestDisplayString(), asm3.GlobalNamespace.GetTypeMembers("C6").Single().ToTestDisplayString()); Assert.Equal(typeC301.ToDisplayString(SymbolDisplayFormat.QualifiedNameArityFormat), asm3.GlobalNamespace.GetTypeMembers("C3").Single(). GetTypeMembers("C301").Single().ToDisplayString(SymbolDisplayFormat.QualifiedNameArityFormat)); Assert.Equal(typeC6.ToDisplayString(SymbolDisplayFormat.QualifiedNameArityFormat), asm3.GlobalNamespace.GetTypeMembers("C6").Single().ToDisplayString(SymbolDisplayFormat.QualifiedNameArityFormat)); Assert.Equal(type3.GetMembers().Length, asm3.GlobalNamespace.GetTypeMembers("C3").Single().GetMembers().Length); Assert.Equal(type3.GetTypeMembers().Length, asm3.GlobalNamespace.GetTypeMembers("C3").Single().GetTypeMembers().Length); Assert.Same(typeC301, type3.GetTypeMembers("C301", 0).Single()); Assert.Equal(0, type3.Arity); Assert.Equal(1, typeC6.Arity); Assert.NotNull(type3.BaseType); Assert.Equal("System.Object", type3.BaseType.ToTestDisplayString()); Assert.Equal(Accessibility.Public, type3.DeclaredAccessibility); Assert.Equal(Accessibility.Internal, typeC302.DeclaredAccessibility); Assert.Equal(0, type3.Interfaces.Length); Assert.Equal(1, typeC301.Interfaces.Length); Assert.Equal("I1", typeC301.Interfaces.Single().Name); Assert.False(type3.IsAbstract); Assert.True(typeC301.IsAbstract); Assert.False(type3.IsSealed); Assert.False(type3.IsStatic); Assert.Equal(0, type3.TypeArguments.Length); Assert.Equal(0, type3.TypeParameters.Length); var localC6Params = typeC6.TypeParameters; Assert.Equal(1, localC6Params.Length); Assert.Equal(1, typeC6.TypeArguments.Length); Assert.Same(localC6Params[0], typeC6.TypeArguments[0]); Assert.Same(((RetargetingNamedTypeSymbol)type3).UnderlyingNamedType, asm3.GlobalNamespace.GetTypeMembers("C3").Single()); Assert.Equal(1, ((RetargetingNamedTypeSymbol)type3).Locations.Length); Assert.Equal(TypeKind.Class, type3.TypeKind); Assert.Equal(TypeKind.Interface, asm5[1].GlobalNamespace.GetTypeMembers("I1").Single().TypeKind); var localC6_T = localC6Params[0]; var foo3TypeParam = foo3TypeParams[0]; Assert.Equal(0, localC6_T.ConstraintTypes.Length); Assert.Equal(1, foo3TypeParam.ConstraintTypes.Length); Assert.Same(type4, foo3TypeParam.ConstraintTypes.Single()); Assert.Same(typeC6, localC6_T.ContainingSymbol); Assert.False(foo3TypeParam.HasConstructorConstraint); Assert.True(localC6_T.HasConstructorConstraint); Assert.False(foo3TypeParam.HasReferenceTypeConstraint); Assert.False(foo3TypeParam.HasValueTypeConstraint); Assert.Equal("TFoo3", foo3TypeParam.Name); Assert.Equal("T", localC6_T.Name); Assert.Equal(0, foo3TypeParam.Ordinal); Assert.Equal(0, localC6_T.Ordinal); Assert.Equal(VarianceKind.None, foo3TypeParam.Variance); Assert.Same(((RetargetingTypeParameterSymbol)localC6_T).UnderlyingTypeParameter, asm3.GlobalNamespace.GetTypeMembers("C6").Single().TypeParameters[0]); var ns1 = asm5[1].GlobalNamespace.GetMembers("ns1").OfType<NamespaceSymbol>().Single(); var ns2 = ns1.GetMembers("ns2").OfType<NamespaceSymbol>().Single(); Assert.Equal("ns1.ns2", ns2.ToTestDisplayString()); Assert.Equal(2, ns1.GetMembers().Length); Assert.Equal(1, ns1.GetTypeMembers().Length); Assert.Same(ns1.GetTypeMembers("C304").Single(), ns1.GetTypeMembers("C304", 0).Single()); Assert.Same(asm5[1].Modules[0], asm5[1].Modules[0].GlobalNamespace.ContainingSymbol); Assert.Same(asm5[1].Modules[0].GlobalNamespace, ns1.ContainingSymbol); Assert.Same(asm5[1].Modules[0], ns1.Extent.Module); Assert.Equal(1, ns1.ConstituentNamespaces.Length); Assert.Same(ns1, ns1.ConstituentNamespaces[0]); Assert.False(ns1.IsGlobalNamespace); Assert.True(asm5[1].Modules[0].GlobalNamespace.IsGlobalNamespace); Assert.Same(asm3.Modules[0].GlobalNamespace, ((RetargetingNamespaceSymbol)asm5[1].Modules[0].GlobalNamespace).UnderlyingNamespace); Assert.Same(asm3.Modules[0].GlobalNamespace.GetMembers("ns1").Single(), ((RetargetingNamespaceSymbol)ns1).UnderlyingNamespace); var module3 = (RetargetingModuleSymbol)asm5[1].Modules[0]; Assert.Equal("C3.dll", module3.ToTestDisplayString()); Assert.Equal("C3.dll", module3.Name); Assert.Same(asm5[1], module3.ContainingSymbol); Assert.Same(asm5[1], module3.ContainingAssembly); Assert.Null(module3.ContainingType); var retval5 = type3.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("C8<C4>", retval5.ToTestDisplayString()); var typeC5 = c5.Assembly.GlobalNamespace.GetTypeMembers("C5").Single(); Assert.Same(asm5[1], typeC5.BaseType.ContainingAssembly); Assert.Equal("ns1.C304.C305", typeC5.BaseType.ToTestDisplayString()); Assert.NotEqual(SymbolKind.ErrorType, typeC5.Kind); }
public override IAssembly LoadAssembly(AssemblyIdentity assemblyIdentity) { return(base.LoadAssembly(assemblyIdentity)); }
public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnostics, Location location, MetadataReference reference, AssemblyIdentity identity, MetadataReference equivalentReference, AssemblyIdentity equivalentIdentity) { throw new NotImplementedException(); }
public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnostics, Location location, MetadataReference reference, AssemblyIdentity identity, MetadataReference equivalentReference, AssemblyIdentity equivalentIdentity) { diagnostics.Add(ErrorCode.ERR_DuplicateImportSimple, location, identity.Name, reference.Display ?? identity.GetDisplayName()); }
public void ForwardingErrors() { var il = @" .assembly extern mscorlib { } .assembly extern pe2 { } .assembly pe1 { } .class extern forwarder Forwarded { .assembly extern pe2 } .class extern forwarder NS.Forwarded { .assembly extern pe2 } .class public auto ansi beforefieldinit Dummy extends [mscorlib]System.Object { .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { ldarg.0 call instance void [mscorlib]System.Object::.ctor() ret } } "; var csharp = @" class C { static void M(Dummy d) { } } "; var ilRef = CompileIL(il, prependDefaultHeader: false); var comp = CreateCompilation(csharp, new[] { ilRef }); WithRuntimeInstance(comp, runtime => { var context = CreateMethodContext(runtime, "C.M"); var expectedMissingAssemblyIdentity = new AssemblyIdentity("pe2"); ResultProperties resultProperties; string actualError; ImmutableArray <AssemblyIdentity> actualMissingAssemblyIdentities; context.CompileExpression( "new global::Forwarded()", DkmEvaluationFlags.TreatAsExpression, NoAliases, DebuggerDiagnosticFormatter.Instance, out resultProperties, out actualError, out actualMissingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData: null); Assert.Equal( "error CS1068: The type name 'Forwarded' could not be found in the global namespace. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.", actualError); Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single()); context.CompileExpression( "new Forwarded()", DkmEvaluationFlags.TreatAsExpression, NoAliases, DebuggerDiagnosticFormatter.Instance, out resultProperties, out actualError, out actualMissingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData: null); Assert.Equal( "error CS1070: The type name 'Forwarded' could not be found. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Consider adding a reference to that assembly.", actualError); Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single()); context.CompileExpression( "new NS.Forwarded()", DkmEvaluationFlags.TreatAsExpression, NoAliases, DebuggerDiagnosticFormatter.Instance, out resultProperties, out actualError, out actualMissingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData: null); Assert.Equal( "error CS1069: The type name 'Forwarded' could not be found in the namespace 'NS'. This type has been forwarded to assembly 'pe2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Consider adding a reference to that assembly.", actualError); Assert.Equal(expectedMissingAssemblyIdentity, actualMissingAssemblyIdentities.Single()); }); }
public void ErrorsWithAssemblyIdentityArguments() { var identity = new AssemblyIdentity(GetUniqueName()); Assert.Same(identity, GetMissingAssemblyIdentity(ErrorCode.ERR_NoTypeDef, identity)); }
public void GetDisplayName() { var id = new AssemblyIdentity("foo"); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", new Version(1, 2, 3, 4)); Assert.Equal("foo, Version=1.2.3.4, Culture=neutral, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", cultureName: "en-US"); Assert.Equal("foo, Version=0.0.0.0, Culture=en-US, PublicKeyToken=null", id.GetDisplayName()); id = new AssemblyIdentity("foo", publicKeyOrToken: new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF }.AsImmutableOrNull()); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=0123456789abcdef", id.GetDisplayName(), StringComparer.OrdinalIgnoreCase); id = new AssemblyIdentity("foo", isRetargetable: true); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, Retargetable=Yes", id.GetDisplayName()); id = new AssemblyIdentity("foo", contentType: AssemblyContentType.WindowsRuntime); Assert.Equal("foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime", id.GetDisplayName()); id = new AssemblyIdentity("Foo", publicKeyOrToken: RoPublicKey1, hasPublicKey: true); string dn1 = id.GetDisplayName(); string dn2 = id.GetDisplayName(fullKey: false); Assert.True(ReferenceEquals(dn1, dn2), "cached full name expected"); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=" + StrPublicKeyToken1, dn1); string dnFull = id.GetDisplayName(fullKey: true); Assert.Equal("Foo, Version=0.0.0.0, Culture=neutral, PublicKey=" + StrPublicKey1, dnFull); }
internal NamedTypeSymbol GetTopLevelTypeByMetadataName( ref MetadataTypeName metadataName, AssemblyIdentity assemblyOpt, bool includeReferences, bool isWellKnownType, out (AssemblySymbol, AssemblySymbol) conflicts, DiagnosticBag warnings = null, bool ignoreCorLibraryDuplicatedTypes = false) { conflicts = default; NamedTypeSymbol result; // First try this assembly result = GetTopLevelTypeByMetadataName(this, ref metadataName, assemblyOpt); if (isWellKnownType && !IsValidWellKnownType(result)) { result = null; } // ignore any types of the same name that might be in referenced assemblies (prefer the current assembly): if ((object)result != null || !includeReferences) { return(result); } Debug.Assert(this is SourceAssemblySymbol, "Never include references for a non-source assembly, because they don't know about aliases."); var assemblies = ArrayBuilder <AssemblySymbol> .GetInstance(); // ignore reference aliases if searching for a type from a specific assembly: if (assemblyOpt != null) { assemblies.AddRange(DeclaringCompilation.GetBoundReferenceManager().ReferencedAssemblies); } else { DeclaringCompilation.GetUnaliasedReferencedAssemblies(assemblies); } // Lookup in references foreach (var assembly in assemblies) { Debug.Assert(!(this is SourceAssemblySymbol && assembly.IsMissing)); // Non-source assemblies can have missing references NamedTypeSymbol candidate = GetTopLevelTypeByMetadataName(assembly, ref metadataName, assemblyOpt); if (isWellKnownType && !IsValidWellKnownType(candidate)) { candidate = null; } if ((object)candidate == null) { continue; } if (candidate.IsHiddenByCodeAnalysisEmbeddedAttribute()) { continue; } Debug.Assert(candidate != result); if ((object)result != null) { // duplicate if (ignoreCorLibraryDuplicatedTypes) { if (IsInCorLib(candidate)) { // ignore candidate continue; } if (IsInCorLib(result)) { // drop previous result result = candidate; continue; } } if (warnings == null) { conflicts = (result.ContainingAssembly, candidate.ContainingAssembly); result = null; } else { // The predefined type '{0}' is defined in multiple assemblies in the global alias; using definition from '{1}' warnings.Add(ErrorCode.WRN_MultiplePredefTypes, NoLocation.Singleton, result, result.ContainingAssembly); } break; } result = candidate; } assemblies.Free(); return(result); }
private static int IndexOfMatchingAssembly(AssemblyIdentity referenceIdentity, ImmutableArray<Symbol> assembliesAndModules, AssemblyIdentityComparer assemblyIdentityComparer) { for (int i = 0; i < assembliesAndModules.Length; i++) { var assembly = assembliesAndModules[i] as AssemblySymbol; if (assembly != null && assemblyIdentityComparer.ReferenceMatchesDefinition(referenceIdentity, assembly.Identity)) { return i; } } return -1; }
private static NamedTypeSymbol GetTopLevelTypeByMetadataName(AssemblySymbol assembly, ref MetadataTypeName metadataName, AssemblyIdentity assemblyOpt) { var result = assembly.LookupTopLevelMetadataType(ref metadataName, digThroughForwardedTypes: false); if (!IsAcceptableMatchForGetTypeByMetadataName(result)) { return(null); } if (assemblyOpt != null && !assemblyOpt.Equals(assembly.Identity)) { return(null); } return(result); }
public void MultiTargeting2() { var varMTTestLib1_V1_Name = new AssemblyIdentity("MTTestLib1", new Version("1.0.0.0")); var varC_MTTestLib1_V1 = CreateCompilation(varMTTestLib1_V1_Name, new string[] { // AssemblyPaths.SymbolsTests.V1.MTTestModule1.netmodule @" public class Class1 { } " }, new[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm_MTTestLib1_V1 = varC_MTTestLib1_V1.SourceAssembly().BoundReferences(); var varMTTestLib2_Name = new AssemblyIdentity("MTTestLib2"); var varC_MTTestLib2 = CreateCompilation(varMTTestLib2_Name, new string[] { // AssemblyPaths.SymbolsTests.V1.MTTestModule2.netmodule @" public class Class4 { Class1 Foo() { return null; } public Class1 Bar; } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib1_V1.ToMetadataReference() }); var asm_MTTestLib2 = varC_MTTestLib2.SourceAssembly().BoundReferences(); Assert.Same(asm_MTTestLib2[0], asm_MTTestLib1_V1[0]); Assert.Same(asm_MTTestLib2[1], varC_MTTestLib1_V1.SourceAssembly()); var c2 = CreateCompilation(new AssemblyIdentity("c2"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V1.ToMetadataReference() }); var asm2 = c2.SourceAssembly().BoundReferences(); Assert.Same(asm2[0], asm_MTTestLib1_V1[0]); Assert.Same(asm2[1], varC_MTTestLib2.SourceAssembly()); Assert.Same(asm2[2], varC_MTTestLib1_V1.SourceAssembly()); Assert.Equal("MTTestLib2", asm2[1].Identity.Name); Assert.Equal(2, (from a in asm2[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[2]) select a).Count()); var retval1 = asm2[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval1.Kind); Assert.Same(retval1, asm2[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm2[2].Identity.Name); Assert.Equal(1, asm2[2].Identity.Version.Major); Assert.Equal(1, (from a in asm2[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[2].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); var varMTTestLib1_V2_Name = new AssemblyIdentity("MTTestLib1", new Version("2.0.0.0")); var varC_MTTestLib1_V2 = CreateCompilation(varMTTestLib1_V2_Name, new string[] { // AssemblyPaths.SymbolsTests.V2.MTTestModule1.netmodule @" public class Class1 { } public class Class2 { } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm_MTTestLib1_V2 = varC_MTTestLib1_V2.SourceAssembly().BoundReferences(); var varMTTestLib3_Name = new AssemblyIdentity("MTTestLib3"); var varC_MTTestLib3 = CreateCompilation(varMTTestLib3_Name, new string[] { // AssemblyPaths.SymbolsTests.V2.MTTestModule3.netmodule @" public class Class5 { Class1 Foo1() { return null; } Class2 Foo2() { return null; } Class4 Foo3() { return null; } Class1 Bar1; Class2 Bar2; Class4 Bar3; } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V2.ToMetadataReference() }); var asm_MTTestLib3 = varC_MTTestLib3.SourceAssembly().BoundReferences(); Assert.Same(asm_MTTestLib3[0], asm_MTTestLib1_V1[0]); Assert.NotSame(asm_MTTestLib3[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm_MTTestLib3[2], varC_MTTestLib1_V1.SourceAssembly()); var c3 = CreateCompilation(new AssemblyIdentity("c3"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V2.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference() }); var asm3 = c3.SourceAssembly().BoundReferences(); Assert.Same(asm3[0], asm_MTTestLib1_V1[0]); Assert.Same(asm3[1], asm_MTTestLib3[1]); Assert.Same(asm3[2], asm_MTTestLib3[2]); Assert.Same(asm3[3], varC_MTTestLib3.SourceAssembly()); Assert.Equal("MTTestLib2", asm3[1].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm3[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(1, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); var retval2 = asm3[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval2.Kind); Assert.Same(retval2, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm3[2].Identity.Name); Assert.NotSame(asm3[2], asm2[2]); Assert.NotSame(asm3[2].DeclaringCompilation, asm2[2].DeclaringCompilation); Assert.Equal(2, asm3[2].Identity.Version.Major); Assert.Equal(1, (from a in asm3[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[2].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal("MTTestLib3", asm3[3].Identity.Name); Assert.Equal(3, (from a in asm3[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[1]) select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); var type1 = asm3[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); var retval3 = type1.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval3.Kind); Assert.Same(retval3, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); var retval4 = type1.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval4.Kind); Assert.Same(retval4, asm3[2].GlobalNamespace.GetMembers("Class2").Single()); var retval5 = type1.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval5.Kind); Assert.Same(retval5, asm3[1].GlobalNamespace.GetMembers("Class4").Single()); var varMTTestLib1_V3_Name = new AssemblyIdentity("MTTestLib1", new Version("3.0.0.0")); var varC_MTTestLib1_V3 = CreateCompilation(varMTTestLib1_V3_Name, new string[] { // AssemblyPaths.SymbolsTests.V3.MTTestModule1.netmodule @" public class Class1 { } public class Class2 { } public class Class3 { } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }); var asm_MTTestLib1_V3 = varC_MTTestLib1_V3.SourceAssembly().BoundReferences(); var varMTTestLib4_Name = new AssemblyIdentity("MTTestLib4"); var varC_MTTestLib4 = CreateCompilation(varMTTestLib4_Name, new string[] { // AssemblyPaths.SymbolsTests.V3.MTTestModule4.netmodule @" public class Class6 { Class1 Foo1() { return null; } Class2 Foo2() { return null; } Class3 Foo3() { return null; } Class4 Foo4() { return null; } Class5 Foo5() { return null; } Class1 Bar1; Class2 Bar2; Class3 Bar3; Class4 Bar4; Class5 Bar5; } " }, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V3.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference() }); var asm_MTTestLib4 = varC_MTTestLib4.SourceAssembly().BoundReferences(); Assert.Same(asm_MTTestLib4[0], asm_MTTestLib1_V1[0]); Assert.NotSame(asm_MTTestLib4[1], varC_MTTestLib2.SourceAssembly()); Assert.Same(asm_MTTestLib4[2], varC_MTTestLib1_V3.SourceAssembly()); Assert.NotSame(asm_MTTestLib4[3], varC_MTTestLib3.SourceAssembly()); var c4 = CreateCompilation(new AssemblyIdentity("c4"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V3.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference(), varC_MTTestLib4.ToMetadataReference() }); var asm4 = c4.SourceAssembly().BoundReferences(); Assert.Same(asm4[0], asm_MTTestLib1_V1[0]); Assert.Same(asm4[1], asm_MTTestLib4[1]); Assert.Same(asm4[2], asm_MTTestLib4[2]); Assert.Same(asm4[3], asm_MTTestLib4[3]); Assert.Same(asm4[4], varC_MTTestLib4.SourceAssembly()); Assert.Equal("MTTestLib2", asm4[1].Identity.Name); Assert.NotSame(asm4[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm4[1], asm2[1]); Assert.NotSame(asm4[1], asm3[1]); Assert.Same(((RetargetingAssemblySymbol)asm4[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); var retval6 = asm4[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval6.Kind); Assert.Same(retval6, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm4[2].Identity.Name); Assert.NotSame(asm4[2], asm2[2]); Assert.NotSame(asm4[2], asm3[2]); Assert.NotSame(asm4[2].DeclaringCompilation, asm2[2].DeclaringCompilation); Assert.NotSame(asm4[2].DeclaringCompilation, asm3[2].DeclaringCompilation); Assert.Equal(3, asm4[2].Identity.Version.Major); Assert.Equal(1, (from a in asm4[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[2].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal("MTTestLib3", asm4[3].Identity.Name); Assert.NotSame(asm4[3], asm3[3]); Assert.Same(((RetargetingAssemblySymbol)asm4[3]).UnderlyingAssembly, asm3[3]); Assert.Equal(3, (from a in asm4[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); var type2 = asm4[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); var retval7 = type2.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval7.Kind); Assert.Same(retval7, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); var retval8 = type2.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval8.Kind); Assert.Same(retval8, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); var retval9 = type2.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval9.Kind); Assert.Same(retval9, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm4[4].Identity.Name); Assert.Equal(4, (from a in asm4[4].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[3]) select a).Count()); var type3 = asm4[4].GlobalNamespace.GetTypeMembers("Class6"). Single(); var retval10 = type3.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval10.Kind); Assert.Same(retval10, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); var retval11 = type3.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval11.Kind); Assert.Same(retval11, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); var retval12 = type3.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval12.Kind); Assert.Same(retval12, asm4[2].GlobalNamespace.GetMembers("Class3").Single()); var retval13 = type3.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval13.Kind); Assert.Same(retval13, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); var retval14 = type3.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval14.Kind); Assert.Same(retval14, asm4[3].GlobalNamespace.GetMembers("Class5").Single()); var c5 = CreateCompilation(new AssemblyIdentity("c5"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib3.ToMetadataReference() }); var asm5 = c5.SourceAssembly().BoundReferences(); Assert.Same(asm5[0], asm2[0]); Assert.True(asm5[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm3[3])); var c6 = CreateCompilation(new AssemblyIdentity("c6"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference() }); var asm6 = c6.SourceAssembly().BoundReferences(); Assert.Same(asm6[0], asm2[0]); Assert.True(asm6[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); var c7 = CreateCompilation(new AssemblyIdentity("c7"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference(), varC_MTTestLib4.ToMetadataReference() }); var asm7 = c7.SourceAssembly().BoundReferences(); Assert.Same(asm7[0], asm2[0]); Assert.True(asm7[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.NotSame(asm7[2], asm3[3]); Assert.NotSame(asm7[2], asm4[3]); Assert.NotSame(asm7[3], asm4[4]); Assert.Equal("MTTestLib3", asm7[2].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[2]).UnderlyingAssembly, asm3[3]); Assert.Equal(2, (from a in asm7[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(1, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); var type4 = asm7[2].GlobalNamespace.GetTypeMembers("Class5"). Single(); var retval15 = type4.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval15.ContainingAssembly.Name); Assert.Equal(0, (from a in asm7 where a != null && a.Name == "MTTestLib1" select a).Count()); var retval16 = type4.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval16.ContainingAssembly.Name); var retval17 = type4.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval17.Kind); Assert.Same(retval17, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm7[3].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[3]).UnderlyingAssembly, asm4[4]); Assert.Equal(3, (from a in asm7[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[2]) select a).Count()); var type5 = asm7[3].GlobalNamespace.GetTypeMembers("Class6"). Single(); var retval18 = type5.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval18.ContainingAssembly.Name); var retval19 = type5.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval19.ContainingAssembly.Name); var retval20 = type5.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval20.ContainingAssembly.Name); var retval21 = type5.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval21.Kind); Assert.Same(retval21, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); var retval22 = type5.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval22.Kind); Assert.Same(retval22, asm7[2].GlobalNamespace.GetMembers("Class5").Single()); // This test shows that simple reordering of references doesn't pick different set of assemblies var c8 = CreateCompilation(new AssemblyIdentity("c8"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib4.ToMetadataReference(), varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference() }); var asm8 = c8.SourceAssembly().BoundReferences(); Assert.Same(asm8[0], asm2[0]); Assert.True(asm8[2].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[1])); Assert.Same(asm8[2], asm7[1]); Assert.True(asm8[3].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[3])); Assert.Same(asm8[3], asm7[2]); Assert.True(asm8[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[4])); Assert.Same(asm8[1], asm7[3]); var c9 = CreateCompilation(new AssemblyIdentity("c9"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib4.ToMetadataReference() }); var asm9 = c9.SourceAssembly().BoundReferences(); Assert.Same(asm9[0], asm2[0]); Assert.True(asm9[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[4])); var c10 = CreateCompilation(new AssemblyIdentity("c10"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, varC_MTTestLib2.ToMetadataReference(), varC_MTTestLib1_V3.ToMetadataReference(), varC_MTTestLib3.ToMetadataReference(), varC_MTTestLib4.ToMetadataReference() }); var asm10 = c10.SourceAssembly().BoundReferences(); Assert.Same(asm10[0], asm2[0]); Assert.Same(asm10[1], asm4[1]); Assert.Same(asm10[2], asm4[2]); Assert.Same(asm10[3], asm4[3]); Assert.Same(asm10[4], asm4[4]); // Run the same tests again to make sure we didn't corrupt prior state by loading additional assemblies Assert.Same(asm2[0], asm_MTTestLib1_V1[0]); Assert.Equal("MTTestLib2", asm2[1].Identity.Name); Assert.Equal(2, (from a in asm2[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Equal(1, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[2]) select a).Count()); retval1 = asm2[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval1.Kind); Assert.Same(retval1, asm2[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm2[2].Identity.Name); Assert.Equal(1, asm2[2].Identity.Version.Major); Assert.Equal(1, (from a in asm2[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[2].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Same(asm_MTTestLib3[0], asm_MTTestLib1_V1[0]); Assert.NotSame(asm_MTTestLib3[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm_MTTestLib3[2], varC_MTTestLib1_V1.SourceAssembly()); Assert.Same(asm3[0], asm_MTTestLib1_V1[0]); Assert.Same(asm3[1], asm_MTTestLib3[1]); Assert.Same(asm3[2], asm_MTTestLib3[2]); Assert.Same(asm3[3], varC_MTTestLib3.SourceAssembly()); Assert.Equal("MTTestLib2", asm3[1].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm3[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(1, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); retval2 = asm3[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval2.Kind); Assert.Same(retval2, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm3[2].Identity.Name); Assert.NotSame(asm3[2], asm2[2]); Assert.NotSame(asm3[2].DeclaringCompilation, asm2[2].DeclaringCompilation); Assert.Equal(2, asm3[2].Identity.Version.Major); Assert.Equal(1, (from a in asm3[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[2].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal("MTTestLib3", asm3[3].Identity.Name); Assert.Equal(3, (from a in asm3[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[1]) select a).Count()); Assert.Equal(1, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); type1 = asm3[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval3 = type1.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval3.Kind); Assert.Same(retval3, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); retval4 = type1.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval4.Kind); Assert.Same(retval4, asm3[2].GlobalNamespace.GetMembers("Class2").Single()); retval5 = type1.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval5.Kind); Assert.Same(retval5, asm3[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Same(asm4[0], asm_MTTestLib1_V1[0]); Assert.Same(asm4[1], asm_MTTestLib4[1]); Assert.Same(asm4[2], asm_MTTestLib4[2]); Assert.Same(asm4[3], asm_MTTestLib4[3]); Assert.Same(asm4[4], varC_MTTestLib4.SourceAssembly()); Assert.Equal("MTTestLib2", asm4[1].Identity.Name); Assert.NotSame(asm4[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm4[1], asm2[1]); Assert.NotSame(asm4[1], asm3[1]); Assert.Same(((RetargetingAssemblySymbol)asm4[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); retval6 = asm4[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval6.Kind); Assert.Same(retval6, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm4[2].Identity.Name); Assert.NotSame(asm4[2], asm2[2]); Assert.NotSame(asm4[2], asm3[2]); Assert.NotSame(asm4[2].DeclaringCompilation, asm2[2].DeclaringCompilation); Assert.NotSame(asm4[2].DeclaringCompilation, asm3[2].DeclaringCompilation); Assert.Equal(3, asm4[2].Identity.Version.Major); Assert.Equal(1, (from a in asm4[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[2].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal("MTTestLib3", asm4[3].Identity.Name); Assert.NotSame(asm4[3], asm3[3]); Assert.Same(((RetargetingAssemblySymbol)asm4[3]).UnderlyingAssembly, asm3[3]); Assert.Equal(3, (from a in asm4[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(1, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); type2 = asm4[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval7 = type2.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval7.Kind); Assert.Same(retval7, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); retval8 = type2.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval8.Kind); Assert.Same(retval8, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); retval9 = type2.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval9.Kind); Assert.Same(retval9, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm4[4].Identity.Name); Assert.Equal(4, (from a in asm4[4].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); Assert.Equal(1, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[3]) select a).Count()); type3 = asm4[4].GlobalNamespace.GetTypeMembers("Class6"). Single(); retval10 = type3.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval10.Kind); Assert.Same(retval10, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); retval11 = type3.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval11.Kind); Assert.Same(retval11, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); retval12 = type3.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval12.Kind); Assert.Same(retval12, asm4[2].GlobalNamespace.GetMembers("Class3").Single()); retval13 = type3.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval13.Kind); Assert.Same(retval13, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); retval14 = type3.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval14.Kind); Assert.Same(retval14, asm4[3].GlobalNamespace.GetMembers("Class5").Single()); Assert.Same(asm5[0], asm2[0]); Assert.True(asm5[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm3[3])); Assert.Same(asm6[0], asm2[0]); Assert.True(asm6[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.Same(asm7[0], asm2[0]); Assert.True(asm7[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.NotSame(asm7[2], asm3[3]); Assert.NotSame(asm7[2], asm4[3]); Assert.NotSame(asm7[3], asm4[4]); Assert.Equal("MTTestLib3", asm7[2].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[2]).UnderlyingAssembly, asm3[3]); Assert.Equal(2, (from a in asm7[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(1, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); type4 = asm7[2].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval15 = type4.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval15.ContainingAssembly.Name); Assert.Equal(0, (from a in asm7 where a != null && a.Name == "MTTestLib1" select a).Count()); retval16 = type4.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval16.ContainingAssembly.Name); retval17 = type4.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval17.Kind); Assert.Same(retval17, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm7[3].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[3]).UnderlyingAssembly, asm4[4]); Assert.Equal(3, (from a in asm7[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); Assert.Equal(1, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[2]) select a).Count()); type5 = asm7[3].GlobalNamespace.GetTypeMembers("Class6"). Single(); retval18 = type5.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval18.ContainingAssembly.Name); retval19 = type5.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval19.ContainingAssembly.Name); retval20 = type5.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", retval20.ContainingAssembly.Name); retval21 = type5.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval21.Kind); Assert.Same(retval21, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); retval22 = type5.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval22.Kind); Assert.Same(retval22, asm7[2].GlobalNamespace.GetMembers("Class5").Single()); }
AssemblySymbol CreateAssemblyFromIdentity(MetadataReferenceResolver resolver, AssemblyIdentity identity, string basePath, List <PEModuleSymbol> modules) { PEAssemblySymbol ass; if (!_observedMetadata.TryGetValue(identity, out ass)) { // temporary: lookup ignoring minor version number foreach (var pair in _observedMetadata) { // TODO: _identityComparer if (pair.Key.Name.Equals(identity.Name, StringComparison.OrdinalIgnoreCase) && (pair.Key.Version.Major == identity.Version.Major || identity.Version == new Version(0, 0, 0, 0))) { _observedMetadata[identity] = pair.Value; return(pair.Value); } } // if (resolver != null) { string keytoken = string.Join("", identity.PublicKeyToken.Select(b => b.ToString("x2"))); var pes = resolver.ResolveReference(identity.Name + ".dll", basePath, MetadataReferenceProperties.Assembly) .Concat(resolver.ResolveReference($"{identity.Name}/v4.0_{identity.Version}__{keytoken}/{identity.Name}.dll", basePath, MetadataReferenceProperties.Assembly)); var pe = pes.FirstOrDefault(); if (pe != null) { _observedMetadata[identity] = ass = PEAssemblySymbol.Create(pe, isLinked: false); ass.SetCorLibrary(_lazyCorLibrary); modules.AddRange(ass.Modules.Cast <PEModuleSymbol>()); } } if (ass == null) { //_diagnostics.Add(Location.None, Errors.ErrorCode.ERR_MetadataFileNotFound, identity); return(new MissingAssemblySymbol(identity)); } } return(ass); }
public override PortableExecutableReference ResolveMissingAssembly(MetadataReference definition, AssemblyIdentity referenceIdentity) { ResolutionAttempts.Add(new ReferenceAndIdentity(definition, referenceIdentity)); string nameAndVersion = referenceIdentity.Name + (referenceIdentity.Version != AssemblyIdentity.NullVersion ? $", {referenceIdentity.Version}" : ""); return(_map.TryGetValue(nameAndVersion, out var reference) ? (PortableExecutableReference)reference : null); }
private static AssemblyIdentityAndLocation FindHighestVersionOrFirstMatchingIdentity(AssemblyIdentity identity, IEnumerable <AssemblyIdentityAndLocation> assemblies) { var candidate = default(AssemblyIdentityAndLocation); foreach (var assembly in assemblies) { if (DesktopAssemblyIdentityComparer.Default.ReferenceMatchesDefinition(identity, assembly.Identity)) { if (candidate.Identity == null || candidate.Identity.Version < assembly.Identity.Version) { candidate = assembly; } } } return(candidate); }
internal Assembly ResolveAssembly(AssemblyIdentity identity, string loadDirectoryOpt) { // if the referring assembly is already loaded by our loader, load from its directory: if (loadDirectoryOpt != null) { Assembly assembly; var conflictingLoadedAssemblyOpt = default(LoadedAssemblyInfo); var loadedAssemblyWithEqualNameAndVersionOpt = default(LoadedAssemblyInfo); lock (_referencesLock) { // Has the file already been loaded? assembly = TryGetAssemblyLoadedFromPath(identity, loadDirectoryOpt); if (assembly != null) { return(assembly); } // Has an assembly with the same name and version been loaded (possibly from a different directory)? List <LoadedAssemblyInfo> loadedInfos; if (_loadedAssembliesBySimpleName.TryGetValue(identity.Name, out loadedInfos)) { // Desktop FX: A weak-named assembly conflicts with another weak-named assembly of the same simple name, // unless we find an assembly whose identity matches exactly and whose content is exactly the same. // TODO: We shouldn't block this on CoreCLR. https://github.com/dotnet/roslyn/issues/38621 if (!identity.IsStrongName) { conflictingLoadedAssemblyOpt = loadedInfos.FirstOrDefault(info => !info.Identity.IsStrongName); } loadedAssemblyWithEqualNameAndVersionOpt = loadedInfos.FirstOrDefault(info => AssemblyIdentityComparer.SimpleNameComparer.Equals(info.Identity.Name, identity.Name) && info.Identity.Version == identity.Version); } } string assemblyFilePathOpt = FindExistingAssemblyFile(identity.Name, loadDirectoryOpt); if (assemblyFilePathOpt != null) { // TODO: Stop using reflection once ModuleVersionId property once is available in Core contract. if (!loadedAssemblyWithEqualNameAndVersionOpt.IsDefault) { Guid mvid; if (TryReadMvid(assemblyFilePathOpt, out mvid) && loadedAssemblyWithEqualNameAndVersionOpt.Assembly.ManifestModule.ModuleVersionId == mvid) { return(loadedAssemblyWithEqualNameAndVersionOpt.Assembly); } // error: attempt to load an assembly with the same identity as already loaded assembly but different content throw new InteractiveAssemblyLoaderException( string.Format(null, ScriptingResources.AssemblyAlreadyLoaded, identity.Name, identity.Version, loadedAssemblyWithEqualNameAndVersionOpt.LocationOpt, assemblyFilePathOpt) ); } // TODO: Desktop FX only https://github.com/dotnet/roslyn/issues/38621 if (!conflictingLoadedAssemblyOpt.IsDefault) { // error: attempt to load an assembly with the same identity as already loaded assembly but different content throw new InteractiveAssemblyLoaderException( string.Format(null, ScriptingResources.AssemblyAlreadyLoadedNotSigned, identity.Name, conflictingLoadedAssemblyOpt.LocationOpt, assemblyFilePathOpt) ); } assembly = ShadowCopyAndLoadDependency(assemblyFilePathOpt).Assembly; if (assembly != null) { return(assembly); } } } return(GetOrLoadKnownAssembly(identity)); }
private static void ReadCSharpNativeImportsInfo( ISymUnmanagedReader3 reader, EESymbolProvider <TTypeSymbol, TLocalSymbol> symbolProvider, int methodToken, int methodVersion, out ImmutableArray <ImmutableArray <ImportRecord> > importRecordGroups, out ImmutableArray <ExternAliasRecord> externAliasRecords) { ImmutableArray <string> externAliasStrings; var importStringGroups = CustomDebugInfoReader.GetCSharpGroupedImportStrings( methodToken, KeyValuePairUtil.Create(reader, methodVersion), getMethodCustomDebugInfo: (token, arg) => GetCustomDebugInfoBytes(arg.Key, token, arg.Value), getMethodImportStrings: (token, arg) => GetImportStrings(arg.Key, token, arg.Value), externAliasStrings: out externAliasStrings); Debug.Assert(importStringGroups.IsDefault == externAliasStrings.IsDefault); ArrayBuilder <ImmutableArray <ImportRecord> >?importRecordGroupBuilder = null; ArrayBuilder <ExternAliasRecord>?externAliasRecordBuilder = null; if (!importStringGroups.IsDefault) { importRecordGroupBuilder = ArrayBuilder <ImmutableArray <ImportRecord> > .GetInstance(importStringGroups.Length); foreach (var importStringGroup in importStringGroups) { var groupBuilder = ArrayBuilder <ImportRecord> .GetInstance(importStringGroup.Length); foreach (var importString in importStringGroup) { if (TryCreateImportRecordFromCSharpImportString(symbolProvider, importString, out var record)) { groupBuilder.Add(record); } else { Debug.WriteLine($"Failed to parse import string {importString}"); } } importRecordGroupBuilder.Add(groupBuilder.ToImmutableAndFree()); } if (!externAliasStrings.IsDefault) { externAliasRecordBuilder = ArrayBuilder <ExternAliasRecord> .GetInstance(externAliasStrings.Length); foreach (var externAliasString in externAliasStrings) { if (!CustomDebugInfoReader.TryParseCSharpImportString(externAliasString, out var alias, out var externAlias, out var target, out var kind)) { Debug.WriteLine($"Unable to parse extern alias '{externAliasString}'"); continue; } Debug.Assert(kind == ImportTargetKind.Assembly, "Programmer error: How did a non-assembly get in the extern alias list?"); RoslynDebug.Assert(alias != null); // Name of the extern alias. RoslynDebug.Assert(externAlias == null); // Not used. RoslynDebug.Assert(target != null); // Name of the target assembly. if (!AssemblyIdentity.TryParseDisplayName(target, out var targetIdentity)) { Debug.WriteLine($"Unable to parse target of extern alias '{externAliasString}'"); continue; } externAliasRecordBuilder.Add(new ExternAliasRecord(alias, targetIdentity)); } } } importRecordGroups = importRecordGroupBuilder?.ToImmutableAndFree() ?? ImmutableArray <ImmutableArray <ImportRecord> > .Empty; externAliasRecords = externAliasRecordBuilder?.ToImmutableAndFree() ?? ImmutableArray <ExternAliasRecord> .Empty; }
private void TestParseDisplayName(string displayName, AssemblyIdentity expected, AssemblyIdentityParts expectedParts, AssemblyIdentity expectedFusion) { var fusion = FusionAssemblyIdentity.ToAssemblyIdentity(FusionAssemblyIdentity.ToAssemblyNameObject(displayName)); Assert.Equal(expectedFusion, fusion); AssemblyIdentity id = null; AssemblyIdentityParts actualParts; bool success = AssemblyIdentity.TryParseDisplayName(displayName, out id, out actualParts); Assert.Equal(expected, id); Assert.Equal(success, id != null); Assert.Equal(expectedParts, actualParts); }
internal override ImmutableArray <AssemblyIdentity> GetMissingAssemblyIdentities(Diagnostic diagnostic, AssemblyIdentity linqLibrary) { return(GetMissingAssemblyIdentitiesHelper((ErrorCode)diagnostic.Code, diagnostic.Arguments, linqLibrary)); }
/// <remarks> /// Internal for testing. /// </remarks> internal static ImmutableArray <AssemblyIdentity> GetMissingAssemblyIdentitiesHelper(ErrorCode code, IReadOnlyList <object> arguments, AssemblyIdentity linqLibrary) { Debug.Assert(linqLibrary != null); switch (code) { case ErrorCode.ERR_NoTypeDef: case ErrorCode.ERR_GlobalSingleTypeNameNotFoundFwd: case ErrorCode.ERR_DottedTypeNameNotFoundInNSFwd: case ErrorCode.ERR_SingleTypeNameNotFoundFwd: case ErrorCode.ERR_NameNotInContextPossibleMissingReference: // Probably can't happen. foreach (var argument in arguments) { var identity = (argument as AssemblyIdentity) ?? (argument as AssemblySymbol)?.Identity; if (identity != null && !identity.Equals(MissingCorLibrarySymbol.Instance.Identity)) { return(ImmutableArray.Create(identity)); } } break; case ErrorCode.ERR_DottedTypeNameNotFoundInNS: if (arguments.Count == 2) { var namespaceName = arguments[0] as string; var containingNamespace = arguments[1] as NamespaceSymbol; if (namespaceName != null && (object)containingNamespace != null && containingNamespace.ConstituentNamespaces.Any(n => n.ContainingAssembly.Identity.IsWindowsAssemblyIdentity())) { // This is just a heuristic, but it has the advantage of being portable, particularly // across different versions of (desktop) windows. var identity = new AssemblyIdentity($"{containingNamespace.ToDisplayString()}.{namespaceName}", contentType: System.Reflection.AssemblyContentType.WindowsRuntime); return(ImmutableArray.Create(identity)); } } break; case ErrorCode.ERR_NoSuchMemberOrExtension: // Commonly, but not always, caused by absence of System.Core. case ErrorCode.ERR_DynamicAttributeMissing: case ErrorCode.ERR_DynamicRequiredTypesMissing: // MSDN says these might come from System.Dynamic.Runtime case ErrorCode.ERR_QueryNoProviderStandard: case ErrorCode.ERR_ExtensionAttrNotFound: // Probably can't happen. return(ImmutableArray.Create(linqLibrary)); case ErrorCode.ERR_BadAwaitArg_NeedSystem: Debug.Assert(false, "Roslyn no longer produces ERR_BadAwaitArg_NeedSystem"); break; } return(default(ImmutableArray <AssemblyIdentity>)); }
protected IVTConclusion PerformIVTCheck(ImmutableArray <byte> key, AssemblyIdentity otherIdentity) { // This gets a bit complicated. Let's break it down. // // First off, let's assume that the "other" assembly is Smith.DLL, that the "this" // assembly is "Jones.DLL", and that Smith has named Jones as a friend. Whether we // allow Jones to see internals of Smith depends on these four factors: // // q1) Is Smith strong-named? // q2) Did Smith name Jones as a friend via a strong name? // q3) Is Jones strong-named? // q4) Does Smith give a strong-name for Jones that matches our strong name? // // Before we dive into the details, we should mention two additional facts: // // * If the answer to q1 is "yes", and Smith was compiled by the C# compiler, then q2 must be "yes" also. // Strong-named Smith must only be friends with strong-named Jones. See the blog article // http://blogs.msdn.com/b/ericlippert/archive/2009/06/04/alas-smith-and-jones.aspx // for an explanation of why this feature is desirable. // // Now, just because the compiler enforces this rule does not mean that we will never run into // a scenario where Smith is strong-named and names Jones via a weak name. Not all assemblies // were compiled with the C# compiler. We still need to deal sensibly with this situation. // We do so by ignoring the problem; if strong-named Smith extends friendship to weak-named // Jones then we're done; any assembly named Jones is a friend of Smith. // // Incidentally, the compiler produces error CS1726, ERR_FriendAssemblySNReq, when compiling // a strong-named Smith that names a weak-named Jones as its friend. // // * If the answer to q1 is "no" and the answer to q3 is "yes" then we are in a situation where // strong-named Jones is referencing weak-named Smith, which is illegal. In the dev10 compiler // we do not give an error about this until emit time. In Roslyn we have a new error, CS7029, // which we give before emit time when we detect that weak-named Smith has given friend access // to strong-named Jones, which then references Smith. However, we still want to give friend // access to Jones for the purposes of semantic analysis. // // TODO: Roslyn does not yet give an error in other circumstances whereby a strong-named assembly // TODO: references a weak-named assembly. // // Let's make a chart that illustrates all the possible answers to these four questions, and // what the resulting accessibility should be: // // case q1 q2 q3 q4 Result Explanation // 1 YES YES YES YES SUCCESS Smith has named this strong-named Jones as a friend. // 2 YES YES YES NO NO MATCH Smith has named a different strong-named Jones as a friend. // 3 YES YES NO NO NO MATCH Smith has named a strong-named Jones as a friend, but this Jones is weak-named. // 4 YES NO YES NO SUCCESS Smith has improperly (*) named any Jones as its friend. But we honor its offer of friendship. // 5 YES NO NO NO SUCCESS Smith has improperly (*) named any Jones as its friend. But we honor its offer of friendship. // 6 NO YES YES YES SUCCESS, BAD REF Smith has named this strong-named Jones as a friend, but Jones should not be referring to a weak-named Smith. // 7 NO YES YES NO NO MATCH Smith has named a different strong-named Jones as a friend. // 8 NO YES NO NO NO MATCH Smith has named a strong-named Jones as a friend, but this Jones is weak-named. // 9 NO NO YES NO SUCCESS, BAD REF Smith has named any Jones as a friend, but Jones should not be referring to a weak-named Smith. // 10 NO NO NO NO SUCCESS Smith has named any Jones as its friend. // // (*) Smith was not built with C#, which would have prevented this. // // This method never returns NoRelationshipClaimed because if control got here, then we know that // Smith named Jones as a friend somehow. // // All that said, we also have an easy out here. Suppose Smith names Jones as a friend, and Jones is // being compiled as a module, not as an assembly. You can only strong-name an assembly. So if this module // is named Jones, and Smith is extending friend access to Jones, then we are going to optimistically // assume that Jones is going to be compiled into an assembly with a matching strong name, if necessary. CSharpCompilation compilation = this.DeclaringCompilation; if (compilation != null && compilation.Options.OutputKind.IsNetModule()) { return(IVTConclusion.Match); } bool q1 = otherIdentity.IsStrongName; bool q2 = !key.IsDefaultOrEmpty; bool q3 = !this.PublicKey.IsDefaultOrEmpty; bool q4 = (q2 & q3) && ByteSequenceComparer.Equals(key, this.PublicKey); // Cases 2, 3, 7 and 8: if (q2 && !q4) { return(IVTConclusion.PublicKeyDoesntMatch); } // Cases 6 and 9: if (!q1 && q3) { return(IVTConclusion.OneSignedOneNot); } // Cases 1, 4, 5 and 10: return(IVTConclusion.Match); }
internal AssemblyQualifiedTypeName(TypeName typeName, AssemblyIdentity assemblyIdentity, bool retargetable) { this.TypeName = typeName; this.AssemblyIdentity = assemblyIdentity; this.Retargetable = retargetable; }
public override Assembly Load(AssemblyIdentity identity, string location = null) { return(Resolve(identity.Name) ?? _assemblyLoader.Load(identity, location)); }
public void Equality() { var assemblies = MetadataTestHelpers.GetSymbolsForReferences(new[] { TestReferences.SymbolsTests.MissingTypes.MissingTypesEquality1, TestReferences.SymbolsTests.MissingTypes.MissingTypesEquality2, TestReferences.SymbolsTests.MDTestLib1, TestReferences.SymbolsTests.MDTestLib2 }); var asm1 = assemblies[0]; var asm1classC = asm1.GlobalNamespace.GetTypeMembers("C").Single(); var asm1m1 = asm1classC.GetMembers("M1").OfType <MethodSymbol>().Single(); var asm1m2 = asm1classC.GetMembers("M2").OfType <MethodSymbol>().Single(); var asm1m3 = asm1classC.GetMembers("M3").OfType <MethodSymbol>().Single(); var asm1m4 = asm1classC.GetMembers("M4").OfType <MethodSymbol>().Single(); var asm1m5 = asm1classC.GetMembers("M5").OfType <MethodSymbol>().Single(); var asm1m6 = asm1classC.GetMembers("M6").OfType <MethodSymbol>().Single(); var asm1m7 = asm1classC.GetMembers("M7").OfType <MethodSymbol>().Single(); var asm1m8 = asm1classC.GetMembers("M8").OfType <MethodSymbol>().Single(); Assert.NotEqual(asm1m2.ReturnType, asm1m1.ReturnType); Assert.NotEqual(asm1m3.ReturnType, asm1m1.ReturnType); Assert.NotEqual(asm1m4.ReturnType, asm1m1.ReturnType); Assert.NotEqual(asm1m5.ReturnType, asm1m4.ReturnType); Assert.NotEqual(asm1m6.ReturnType, asm1m4.ReturnType); Assert.Equal(asm1m7.ReturnType, asm1m1.ReturnType); Assert.Equal(asm1m8.ReturnType, asm1m4.ReturnType); var asm2 = assemblies[1]; var asm2classC = asm2.GlobalNamespace.GetTypeMembers("C").Single(); var asm2m1 = asm2classC.GetMembers("M1").OfType <MethodSymbol>().Single(); var asm2m4 = asm2classC.GetMembers("M4").OfType <MethodSymbol>().Single(); Assert.Equal(asm2m1.ReturnType, asm1m1.ReturnType); Assert.NotSame(asm1m4.ReturnType, asm2m4.ReturnType); Assert.Equal(asm2m4.ReturnType, asm1m4.ReturnType); Assert.Equal(asm1.GetSpecialType(SpecialType.System_Boolean), asm1.GetSpecialType(SpecialType.System_Boolean)); Assert.Equal(asm1.GetSpecialType(SpecialType.System_Boolean), asm2.GetSpecialType(SpecialType.System_Boolean)); MissingMetadataTypeSymbol [] missingTypes1 = new MissingMetadataTypeSymbol[15]; MissingMetadataTypeSymbol [] missingTypes2 = new MissingMetadataTypeSymbol[15]; var defaultName = new AssemblyIdentity("missing"); missingTypes1[0] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 0, true); missingTypes1[1] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 1, true); missingTypes1[2] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test2", 0, true); missingTypes1[3] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 0, true); missingTypes1[4] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 1, true); missingTypes1[5] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test2", 0, true); missingTypes1[6] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm2")).Modules[0], "", "test1", 0, true); missingTypes1[7] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 0, true); missingTypes1[8] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 1, true); missingTypes1[9] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test2", 0, true); missingTypes1[10] = new MissingMetadataTypeSymbol.TopLevel(asm2.Modules[0], "", "test1", 0, true); missingTypes1[11] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 0, true); missingTypes1[12] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 1, true); missingTypes1[13] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test2", 0, true); missingTypes1[14] = new MissingMetadataTypeSymbol.Nested(asm2classC, "test1", 0, true); missingTypes2[0] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 0, true); missingTypes2[1] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test1", 1, true); missingTypes2[2] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(defaultName).Modules[0], "", "test2", 0, true); missingTypes2[3] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 0, true); missingTypes2[4] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test1", 1, true); missingTypes2[5] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm1")).Modules[0], "", "test2", 0, true); missingTypes2[6] = new MissingMetadataTypeSymbol.TopLevel(new MissingAssemblySymbol(new AssemblyIdentity("asm2")).Modules[0], "", "test1", 0, true); missingTypes2[7] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 0, true); missingTypes2[8] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test1", 1, true); missingTypes2[9] = new MissingMetadataTypeSymbol.TopLevel(asm1.Modules[0], "", "test2", 0, true); missingTypes2[10] = new MissingMetadataTypeSymbol.TopLevel(asm2.Modules[0], "", "test1", 0, true); missingTypes2[11] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 0, true); missingTypes2[12] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test1", 1, true); missingTypes2[13] = new MissingMetadataTypeSymbol.Nested(asm1classC, "test2", 0, true); missingTypes2[14] = new MissingMetadataTypeSymbol.Nested(asm2classC, "test1", 0, true); for (int i = 0; i < missingTypes1.Length; i++) { for (int j = 0; j < missingTypes2.Length; j++) { if (i == j) { Assert.Equal(missingTypes2[j], missingTypes1[i]); Assert.Equal(missingTypes1[i], missingTypes2[j]); } else { Assert.NotEqual(missingTypes2[j], missingTypes1[i]); Assert.NotEqual(missingTypes1[i], missingTypes2[j]); } } } var missingAssembly = new MissingAssemblySymbol(new AssemblyIdentity("asm1")); Assert.True(missingAssembly.Equals(missingAssembly)); Assert.NotEqual(new object(), missingAssembly); Assert.False(missingAssembly.Equals(null)); }
private void TestQuotingAndEscaping(string simpleName, string expectedSimpleName) { var ai = new AssemblyIdentity(simpleName); var dn = ai.GetDisplayName(); Assert.Equal(expectedSimpleName + ", Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", dn); TestParseSimpleName(dn, simpleName); }
public void MultiTargeting3() { var varMTTestLib2_Name = new AssemblyIdentity("MTTestLib2"); var varC_MTTestLib2 = CreateCompilation(varMTTestLib2_Name, (string[])null, new[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V1.MTTestLib1.dll, TestReferences.SymbolsTests.V1.MTTestModule2.netmodule }); var asm_MTTestLib2 = varC_MTTestLib2.SourceAssembly().BoundReferences(); var c2 = CreateCompilation(new AssemblyIdentity("c2"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V1.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2) }); var asm2Prime = c2.SourceAssembly().BoundReferences(); var asm2 = new AssemblySymbol[] { asm2Prime[0], asm2Prime[2], asm2Prime[1] }; Assert.Same(asm2[0], asm_MTTestLib2[0]); Assert.Same(asm2[1], varC_MTTestLib2.SourceAssembly()); Assert.Same(asm2[2], asm_MTTestLib2[1]); Assert.Equal("MTTestLib2", asm2[1].Identity.Name); Assert.Equal(4, (from a in asm2[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Equal(2, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[2]) select a).Count()); var retval1 = asm2[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval1, asm2[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Bar").OfType<FieldSymbol>().Single().Type); Assert.NotEqual(SymbolKind.ErrorType, retval1.Kind); Assert.Same(retval1, asm2[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm2[2].Identity.Name); Assert.Equal(1, asm2[2].Identity.Version.Major); Assert.Equal(1, (from a in asm2[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[2].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); var varMTTestLib3_Name = new AssemblyIdentity("MTTestLib3"); var varC_MTTestLib3 = CreateCompilation(varMTTestLib3_Name, null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V2.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2), TestReferences.SymbolsTests.V2.MTTestModule3.netmodule }); var asm_MTTestLib3Prime = varC_MTTestLib3.SourceAssembly().BoundReferences(); var asm_MTTestLib3 = new AssemblySymbol[] { asm_MTTestLib3Prime[0], asm_MTTestLib3Prime[2], asm_MTTestLib3Prime[1] }; Assert.Same(asm_MTTestLib3[0], asm_MTTestLib2[0]); Assert.NotSame(asm_MTTestLib3[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm_MTTestLib3[2], asm_MTTestLib2[1]); var c3 = CreateCompilation(new AssemblyIdentity("c3"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V2.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3) }); var asm3Prime = c3.SourceAssembly().BoundReferences(); var asm3 = new AssemblySymbol[] { asm3Prime[0], asm3Prime[2], asm3Prime[1], asm3Prime[3] }; Assert.Same(asm3[0], asm_MTTestLib2[0]); Assert.Same(asm3[1], asm_MTTestLib3[1]); Assert.Same(asm3[2], asm_MTTestLib3[2]); Assert.Same(asm3[3], varC_MTTestLib3.SourceAssembly()); Assert.Equal("MTTestLib2", asm3[1].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm3[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(4, (from a in asm3[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); var retval2 = asm3[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval2, asm3[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Bar").OfType<FieldSymbol>().Single().Type); Assert.NotEqual(SymbolKind.ErrorType, retval2.Kind); Assert.Same(retval2, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm3[2].Identity.Name); Assert.NotSame(asm3[2], asm2[2]); Assert.NotSame(asm3[2], asm2[2]); Assert.NotSame(((PEAssemblySymbol)asm3[2]).Assembly, ((PEAssemblySymbol)asm2[2]).Assembly); Assert.Equal(2, asm3[2].Identity.Version.Major); Assert.Equal(1, (from a in asm3[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[2].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal("MTTestLib3", asm3[3].Identity.Name); Assert.Equal(6, (from a in asm3[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[1]) select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); var type1 = asm3[3].GlobalNamespace.GetTypeMembers("Class5").Single(); var retval3 = type1.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval3.Kind); Assert.Same(retval3, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); var retval4 = type1.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval4.Kind); Assert.Same(retval4, asm3[2].GlobalNamespace.GetMembers("Class2").Single()); var retval5 = type1.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval5.Kind); Assert.Same(retval5, asm3[1].GlobalNamespace.GetMembers("Class4").Single()); var varMTTestLib4_Name = new AssemblyIdentity("MTTestLib4"); var varC_MTTestLib4 = CreateCompilation(varMTTestLib4_Name, null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V3.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3), TestReferences.SymbolsTests.V3.MTTestModule4.netmodule }); var asm_MTTestLib4Prime = varC_MTTestLib4.SourceAssembly().BoundReferences(); var asm_MTTestLib4 = new AssemblySymbol[] { asm_MTTestLib4Prime[0], asm_MTTestLib4Prime[2], asm_MTTestLib4Prime[1], asm_MTTestLib4Prime[3] }; Assert.Same(asm_MTTestLib4[0], asm_MTTestLib2[0]); Assert.NotSame(asm_MTTestLib4[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm_MTTestLib4[2], asm3[2]); Assert.NotSame(asm_MTTestLib4[2], asm2[2]); Assert.NotSame(asm_MTTestLib4[3], varC_MTTestLib3.SourceAssembly()); var c4 = CreateCompilation(new AssemblyIdentity("c4"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V3.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3), new CSharpCompilationReference(varC_MTTestLib4) }); var asm4Prime = c4.SourceAssembly().BoundReferences(); var asm4 = new AssemblySymbol[] { asm4Prime[0], asm4Prime[2], asm4Prime[1], asm4Prime[3], asm4Prime[4] }; Assert.Same(asm4[0], asm_MTTestLib2[0]); Assert.Same(asm4[1], asm_MTTestLib4[1]); Assert.Same(asm4[2], asm_MTTestLib4[2]); Assert.Same(asm4[3], asm_MTTestLib4[3]); Assert.Same(asm4[4], varC_MTTestLib4.SourceAssembly()); Assert.Equal("MTTestLib2", asm4[1].Identity.Name); Assert.NotSame(asm4[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm4[1], asm2[1]); Assert.NotSame(asm4[1], asm3[1]); Assert.Same(((RetargetingAssemblySymbol)asm4[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(4, (from a in asm4[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); var retval6 = asm4[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval6.Kind); Assert.Same(retval6, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm4[2].Identity.Name); Assert.NotSame(asm4[2], asm2[2]); Assert.NotSame(asm4[2], asm3[2]); Assert.NotSame(((PEAssemblySymbol)asm4[2]).Assembly, ((PEAssemblySymbol)asm2[2]).Assembly); Assert.NotSame(((PEAssemblySymbol)asm4[2]).Assembly, ((PEAssemblySymbol)asm3[2]).Assembly); Assert.Equal(3, asm4[2].Identity.Version.Major); Assert.Equal(1, (from a in asm4[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[2].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal("MTTestLib3", asm4[3].Identity.Name); Assert.NotSame(asm4[3], asm3[3]); Assert.Same(((RetargetingAssemblySymbol)asm4[3]).UnderlyingAssembly, asm3[3]); Assert.Equal(6, (from a in asm4[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); var type2 = asm4[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); var retval7 = type2.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval7.Kind); Assert.Same(retval7, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); var retval8 = type2.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval8.Kind); Assert.Same(retval8, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); var retval9 = type2.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval9.Kind); Assert.Same(retval9, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm4[4].Identity.Name); Assert.Equal(8, (from a in asm4[4].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[3]) select a).Count()); var type3 = asm4[4].GlobalNamespace.GetTypeMembers("Class6"). Single(); var retval10 = type3.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval10.Kind); Assert.Same(retval10, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); var retval11 = type3.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval11.Kind); Assert.Same(retval11, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); var retval12 = type3.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval12.Kind); Assert.Same(retval12, asm4[2].GlobalNamespace.GetMembers("Class3").Single()); var retval13 = type3.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval13.Kind); Assert.Same(retval13, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); var retval14 = type3.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval14.Kind); Assert.Same(retval14, asm4[3].GlobalNamespace.GetMembers("Class5").Single()); var c5 = CreateCompilation(new AssemblyIdentity("c5"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(varC_MTTestLib3) }); var asm5 = c5.SourceAssembly().BoundReferences(); Assert.Same(asm5[0], asm2[0]); Assert.True(asm5[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm3[3])); var c6 = CreateCompilation(new AssemblyIdentity("c6"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(varC_MTTestLib2) }); var asm6 = c6.SourceAssembly().BoundReferences(); Assert.Same(asm6[0], asm2[0]); Assert.True(asm6[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); var c7 = CreateCompilation(new AssemblyIdentity("c7"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3), new CSharpCompilationReference(varC_MTTestLib4) }); var asm7 = c7.SourceAssembly().BoundReferences(); Assert.Same(asm7[0], asm2[0]); Assert.True(asm7[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.NotSame(asm7[2], asm3[3]); Assert.NotSame(asm7[2], asm4[3]); Assert.NotSame(asm7[3], asm4[4]); Assert.Equal("MTTestLib3", asm7[2].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[2]).UnderlyingAssembly, asm3[3]); Assert.Equal(4, (from a in asm7[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(2, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); var type4 = asm7[2].GlobalNamespace.GetTypeMembers("Class5"). Single(); var retval15 = type4.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; AssemblySymbol missingAssembly; missingAssembly = retval15.ContainingAssembly; Assert.True(missingAssembly.IsMissing); Assert.Equal("MTTestLib1", missingAssembly.Identity.Name); var retval16 = type4.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(missingAssembly, retval16.ContainingAssembly); var retval17 = type4.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval17.Kind); Assert.Same(retval17, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm7[3].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[3]).UnderlyingAssembly, asm4[4]); Assert.Equal(6, (from a in asm7[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[2]) select a).Count()); var type5 = asm7[3].GlobalNamespace.GetTypeMembers("Class6"). Single(); var retval18 = type5.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", ((MissingMetadataTypeSymbol)retval18).ContainingAssembly.Identity.Name); var retval19 = type5.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval18.ContainingAssembly, retval19.ContainingAssembly); var retval20 = type5.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval18.ContainingAssembly, retval20.ContainingAssembly); var retval21 = type5.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval21.Kind); Assert.Same(retval21, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); var retval22 = type5.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval22.Kind); Assert.Same(retval22, asm7[2].GlobalNamespace.GetMembers("Class5").Single()); // This test shows that simple reordering of references doesn't pick different set of assemblies var c8 = CreateCompilation(new AssemblyIdentity("c8"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(varC_MTTestLib4), new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3) }); var asm8 = c8.SourceAssembly().BoundReferences(); Assert.Same(asm8[0], asm2[0]); Assert.True(asm8[2].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[1])); Assert.Same(asm8[2], asm7[1]); Assert.True(asm8[3].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[3])); Assert.Same(asm8[3], asm7[2]); Assert.True(asm8[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[4])); Assert.Same(asm8[1], asm7[3]); var c9 = CreateCompilation(new AssemblyIdentity("c9"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, new CSharpCompilationReference(varC_MTTestLib4) }); var asm9 = c9.SourceAssembly().BoundReferences(); Assert.Same(asm9[0], asm2[0]); Assert.True(asm9[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm4[4])); var c10 = CreateCompilation(new AssemblyIdentity("c10"), null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V3.MTTestLib1.dll, new CSharpCompilationReference(varC_MTTestLib2), new CSharpCompilationReference(varC_MTTestLib3), new CSharpCompilationReference(varC_MTTestLib4) }); var asm10Prime = c10.SourceAssembly().BoundReferences(); var asm10 = new AssemblySymbol[] { asm10Prime[0], asm10Prime[2], asm10Prime[1], asm10Prime[3], asm10Prime[4] }; Assert.Same(asm10[0], asm2[0]); Assert.Same(asm10[1], asm4[1]); Assert.Same(asm10[2], asm4[2]); Assert.Same(asm10[3], asm4[3]); Assert.Same(asm10[4], asm4[4]); // Run the same tests again to make sure we didn't corrupt prior state by loading additional assemblies Assert.Same(asm2[0], asm_MTTestLib2[0]); Assert.Equal("MTTestLib2", asm2[1].Identity.Name); Assert.Equal(4, (from a in asm2[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Equal(2, (from a in asm2[1].BoundReferences() where object.ReferenceEquals(a, asm2[2]) select a).Count()); retval1 = asm2[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval1.Kind); Assert.Same(retval1, asm2[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm2[2].Identity.Name); Assert.Equal(1, asm2[2].Identity.Version.Major); Assert.Equal(1, (from a in asm2[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm2[2].BoundReferences() where object.ReferenceEquals(a, asm2[0]) select a).Count()); Assert.Same(asm_MTTestLib3[0], asm_MTTestLib2[0]); Assert.NotSame(asm_MTTestLib3[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm_MTTestLib3[2], asm_MTTestLib2[1]); Assert.Same(asm3[0], asm_MTTestLib2[0]); Assert.Same(asm3[1], asm_MTTestLib3[1]); Assert.Same(asm3[2], asm_MTTestLib3[2]); Assert.Same(asm3[3], varC_MTTestLib3.SourceAssembly()); Assert.Equal("MTTestLib2", asm3[1].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm3[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(4, (from a in asm3[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(2, (from a in asm3[1].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); retval2 = asm3[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval2.Kind); Assert.Same(retval2, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm3[2].Identity.Name); Assert.NotSame(asm3[2], asm2[2]); Assert.NotSame(((PEAssemblySymbol)asm3[2]).Assembly, ((PEAssemblySymbol)asm2[2]).Assembly); Assert.Equal(2, asm3[2].Identity.Version.Major); Assert.Equal(1, (from a in asm3[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm3[2].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal("MTTestLib3", asm3[3].Identity.Name); Assert.Equal(6, (from a in asm3[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[0]) select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[1]) select a).Count()); Assert.Equal(2, (from a in asm3[3].BoundReferences() where object.ReferenceEquals(a, asm3[2]) select a).Count()); type1 = asm3[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval3 = type1.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval3.Kind); Assert.Same(retval3, asm3[2].GlobalNamespace.GetMembers("Class1").Single()); retval4 = type1.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval4.Kind); Assert.Same(retval4, asm3[2].GlobalNamespace.GetMembers("Class2").Single()); retval5 = type1.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval5.Kind); Assert.Same(retval5, asm3[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Same(asm4[0], asm_MTTestLib2[0]); Assert.Same(asm4[1], asm_MTTestLib4[1]); Assert.Same(asm4[2], asm_MTTestLib4[2]); Assert.Same(asm4[3], asm_MTTestLib4[3]); Assert.Same(asm4[4], varC_MTTestLib4.SourceAssembly()); Assert.Equal("MTTestLib2", asm4[1].Identity.Name); Assert.NotSame(asm4[1], varC_MTTestLib2.SourceAssembly()); Assert.NotSame(asm4[1], asm2[1]); Assert.NotSame(asm4[1], asm3[1]); Assert.Same(((RetargetingAssemblySymbol)asm4[1]).UnderlyingAssembly, varC_MTTestLib2.SourceAssembly()); Assert.Equal(4, (from a in asm4[1].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[1].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); retval6 = asm4[1].GlobalNamespace.GetTypeMembers("Class4"). Single(). GetMembers("Foo").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval6.Kind); Assert.Same(retval6, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); Assert.Equal("MTTestLib1", asm4[2].Identity.Name); Assert.NotSame(asm4[2], asm2[2]); Assert.NotSame(asm4[2], asm3[2]); Assert.NotSame(((PEAssemblySymbol)asm4[2]).Assembly, ((PEAssemblySymbol)asm2[2]).Assembly); Assert.NotSame(((PEAssemblySymbol)asm4[2]).Assembly, ((PEAssemblySymbol)asm3[2]).Assembly); Assert.Equal(3, asm4[2].Identity.Version.Major); Assert.Equal(1, (from a in asm4[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(1, (from a in asm4[2].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal("MTTestLib3", asm4[3].Identity.Name); Assert.NotSame(asm4[3], asm3[3]); Assert.Same(((RetargetingAssemblySymbol)asm4[3]).UnderlyingAssembly, asm3[3]); Assert.Equal(6, (from a in asm4[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(2, (from a in asm4[3].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); type2 = asm4[3].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval7 = type2.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval7.Kind); Assert.Same(retval7, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); retval8 = type2.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval8.Kind); Assert.Same(retval8, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); retval9 = type2.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval9.Kind); Assert.Same(retval9, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm4[4].Identity.Name); Assert.Equal(8, (from a in asm4[4].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[0]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[1]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[2]) select a).Count()); Assert.Equal(2, (from a in asm4[4].BoundReferences() where object.ReferenceEquals(a, asm4[3]) select a).Count()); type3 = asm4[4].GlobalNamespace.GetTypeMembers("Class6"). Single(); retval10 = type3.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval10.Kind); Assert.Same(retval10, asm4[2].GlobalNamespace.GetMembers("Class1").Single()); retval11 = type3.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval11.Kind); Assert.Same(retval11, asm4[2].GlobalNamespace.GetMembers("Class2").Single()); retval12 = type3.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval12.Kind); Assert.Same(retval12, asm4[2].GlobalNamespace.GetMembers("Class3").Single()); retval13 = type3.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval13.Kind); Assert.Same(retval13, asm4[1].GlobalNamespace.GetMembers("Class4").Single()); retval14 = type3.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval14.Kind); Assert.Same(retval14, asm4[3].GlobalNamespace.GetMembers("Class5").Single()); Assert.Same(asm5[0], asm2[0]); Assert.True(asm5[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(asm3[3])); Assert.Same(asm6[0], asm2[0]); Assert.True(asm6[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.Same(asm7[0], asm2[0]); Assert.True(asm7[1].RepresentsTheSameAssemblyButHasUnresolvedReferencesByComparisonTo(varC_MTTestLib2.SourceAssembly())); Assert.NotSame(asm7[2], asm3[3]); Assert.NotSame(asm7[2], asm4[3]); Assert.NotSame(asm7[3], asm4[4]); Assert.Equal("MTTestLib3", asm7[2].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[2]).UnderlyingAssembly, asm3[3]); Assert.Equal(4, (from a in asm7[2].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(2, (from a in asm7[2].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); type4 = asm7[2].GlobalNamespace.GetTypeMembers("Class5"). Single(); retval15 = type4.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; missingAssembly = retval15.ContainingAssembly; Assert.True(missingAssembly.IsMissing); Assert.Equal("MTTestLib1", missingAssembly.Identity.Name); retval16 = type4.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(missingAssembly, retval16.ContainingAssembly); retval17 = type4.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval17.Kind); Assert.Same(retval17, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); Assert.Equal("MTTestLib4", asm7[3].Identity.Name); Assert.Same(((RetargetingAssemblySymbol)asm7[3]).UnderlyingAssembly, asm4[4]); Assert.Equal(6, (from a in asm7[3].BoundReferences() where !a.IsMissing select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[0]) select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[1]) select a).Count()); Assert.Equal(2, (from a in asm7[3].BoundReferences() where object.ReferenceEquals(a, asm7[2]) select a).Count()); type5 = asm7[3].GlobalNamespace.GetTypeMembers("Class6"). Single(); retval18 = type5.GetMembers("Foo1").OfType<MethodSymbol>().Single().ReturnType; Assert.Equal("MTTestLib1", ((MissingMetadataTypeSymbol)retval18).ContainingAssembly.Identity.Name); retval19 = type5.GetMembers("Foo2").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval18.ContainingAssembly, retval19.ContainingAssembly); retval20 = type5.GetMembers("Foo3").OfType<MethodSymbol>().Single().ReturnType; Assert.Same(retval18.ContainingAssembly, retval20.ContainingAssembly); retval21 = type5.GetMembers("Foo4").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval21.Kind); Assert.Same(retval21, asm7[1].GlobalNamespace.GetMembers("Class4").Single()); retval22 = type5.GetMembers("Foo5").OfType<MethodSymbol>().Single().ReturnType; Assert.NotEqual(SymbolKind.ErrorType, retval22.Kind); Assert.Same(retval22, asm7[2].GlobalNamespace.GetMembers("Class5").Single()); }
/// <summary> /// Attempt to construct a <see cref="MetadataReader"/> instance for this module. /// </summary> /// <returns>Returns 'false' for modules with "bad" or missing metadata.</returns> private unsafe static bool TryGetMetadataReader(GetMetadataBytesPtrFunction getMetaDataBytesPtrFunction, AssemblyIdentity assemblyIdentity, out IntPtr ptr, out int size, out MetadataReader reader) { var assemblyName = assemblyIdentity.GetDisplayName(); try { uint uSize; ptr = getMetaDataBytesPtrFunction(assemblyIdentity, out uSize); size = (int)uSize; reader = new MetadataReader((byte *)ptr, size); return(true); } catch (Exception e) when(MetadataUtilities.IsBadOrMissingMetadataException(e, assemblyName)) { ptr = IntPtr.Zero; size = 0; reader = null; return(false); } }
public void MultiTargeting5() { var c1_Name = new AssemblyIdentity("c1"); var text = @" class Module1 { Class4 M1() {} Class4.Class4_1 M2() {} Class4 M3() {} } "; var tree = Parse(text); var c1 = CreateCompilationWithMscorlib(tree, new MetadataReference[] { TestReferences.SymbolsTests.V1.MTTestLib1.dll, TestReferences.SymbolsTests.V1.MTTestModule2.netmodule }); var c2_Name = new AssemblyIdentity("MTTestLib2"); var c2 = CreateCompilation(c2_Name, null, new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib, TestReferences.SymbolsTests.V2.MTTestLib1.dll, new CSharpCompilationReference(c1) }); SourceAssemblySymbol c1AsmSource = (SourceAssemblySymbol)c1.Assembly; PEAssemblySymbol Lib1_V1 = (PEAssemblySymbol)c1AsmSource.Modules[0].GetReferencedAssemblySymbols()[1]; PEModuleSymbol module1 = (PEModuleSymbol)c1AsmSource.Modules[1]; Assert.Equal(LocationKind.MetadataFile, ((MetadataLocation)Lib1_V1.Locations[0]).Kind); SourceAssemblySymbol c2AsmSource = (SourceAssemblySymbol)c2.Assembly; RetargetingAssemblySymbol c1AsmRef = (RetargetingAssemblySymbol)c2AsmSource.Modules[0].GetReferencedAssemblySymbols()[2]; PEAssemblySymbol Lib1_V2 = (PEAssemblySymbol)c2AsmSource.Modules[0].GetReferencedAssemblySymbols()[1]; PEModuleSymbol module2 = (PEModuleSymbol)c1AsmRef.Modules[1]; Assert.Equal(1, Lib1_V1.Identity.Version.Major); Assert.Equal(2, Lib1_V2.Identity.Version.Major); Assert.NotEqual(module1, module2); Assert.Same(module1.Module, module2.Module); NamedTypeSymbol classModule1 = c1AsmRef.Modules[0].GlobalNamespace.GetTypeMembers("Module1").Single(); MethodSymbol m1 = classModule1.GetMembers("M1").OfType<MethodSymbol>().Single(); MethodSymbol m2 = classModule1.GetMembers("M2").OfType<MethodSymbol>().Single(); MethodSymbol m3 = classModule1.GetMembers("M3").OfType<MethodSymbol>().Single(); Assert.Same(module2, m1.ReturnType.ContainingModule); Assert.Same(module2, m2.ReturnType.ContainingModule); Assert.Same(module2, m3.ReturnType.ContainingModule); }
private static ModuleBuilder CreateDynamicModule(AssemblyBuilderAccess access, AssemblyIdentity name, string fileName) { var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name.ToAssemblyName(), access); if (DisableJitOptimizations) { assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder( typeof(DebuggableAttribute).GetConstructor(new[] { typeof(DebuggableAttribute.DebuggingModes) }), new object[] { DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations })); } const string moduleName = "InteractiveModule"; if (access == AssemblyBuilderAccess.RunAndSave) { return(assemblyBuilder.DefineDynamicModule(moduleName, fileName, emitSymbolInfo: false)); } else { return(assemblyBuilder.DefineDynamicModule(moduleName, emitSymbolInfo: false)); } }
private AssemblyName GetAssemblyName(string fullPath) { using (var stream = PortableShim.File.OpenRead(fullPath)) { using (var peReader = new PEReader(stream)) { var reader = peReader.GetMetadataReader(); var assemblyDef = reader.GetAssemblyDefinition(); var name = reader.GetString(assemblyDef.Name); var cultureName = assemblyDef.Culture.IsNil ? null : reader.GetString(assemblyDef.Culture); var publicKeyOrToken = reader.GetBlobContent(assemblyDef.PublicKey); var hasPublicKey = !publicKeyOrToken.IsEmpty; if (publicKeyOrToken.IsEmpty) { publicKeyOrToken = default(ImmutableArray<byte>); } var identity = new AssemblyIdentity( name: name, version: assemblyDef.Version, cultureName: cultureName, publicKeyOrToken: publicKeyOrToken, hasPublicKey: hasPublicKey, isRetargetable: (assemblyDef.Flags & AssemblyFlags.Retargetable) != 0, contentType: (AssemblyContentType)((int)(assemblyDef.Flags & AssemblyFlags.ContentTypeMask) >> 9)); return new AssemblyName(identity.GetDisplayName()); } } }
internal static bool IsReservedAssemblyName(AssemblyIdentity identity) { return(identity.Name.StartsWith(s_globalAssemblyNamePrefix)); }
public static string GetPublicKeyTokenName(this AssemblyIdentity identity) { return(MapPublicKeyTokenToName(identity.GetPublicKeyToken())); }
public ReferenceAndIdentity(MetadataReference reference, AssemblyIdentity identity) { Reference = reference; Identity = identity; }
/// <remarks> /// Internal for testing. /// </remarks> internal static ImmutableArray<AssemblyIdentity> GetMissingAssemblyIdentitiesHelper(ErrorCode code, IReadOnlyList<object> arguments) { switch (code) { case ErrorCode.ERR_NoTypeDef: case ErrorCode.ERR_GlobalSingleTypeNameNotFoundFwd: case ErrorCode.ERR_DottedTypeNameNotFoundInNSFwd: case ErrorCode.ERR_SingleTypeNameNotFoundFwd: case ErrorCode.ERR_NameNotInContextPossibleMissingReference: // Probably can't happen. foreach (var argument in arguments) { var identity = (argument as AssemblyIdentity) ?? (argument as AssemblySymbol)?.Identity; if (identity != null && !identity.Equals(MissingCorLibrarySymbol.Instance.Identity)) { return ImmutableArray.Create(identity); } } break; case ErrorCode.ERR_DottedTypeNameNotFoundInNS: if (arguments.Count == 2) { var namespaceName = arguments[0] as string; var containingNamespace = arguments[1] as NamespaceSymbol; if (namespaceName != null && (object)containingNamespace != null && containingNamespace.ConstituentNamespaces.Any(n => n.ContainingAssembly.Identity.IsWindowsAssemblyIdentity())) { // This is just a heuristic, but it has the advantage of being portable, particularly // across different versions of (desktop) windows. var identity = new AssemblyIdentity($"{containingNamespace.ToDisplayString()}.{namespaceName}", contentType: System.Reflection.AssemblyContentType.WindowsRuntime); return ImmutableArray.Create(identity); } } break; case ErrorCode.ERR_NoSuchMemberOrExtension: // Commonly, but not always, caused by absence of System.Core. case ErrorCode.ERR_DynamicAttributeMissing: case ErrorCode.ERR_DynamicRequiredTypesMissing: // MSDN says these might come from System.Dynamic.Runtime case ErrorCode.ERR_QueryNoProviderStandard: case ErrorCode.ERR_ExtensionAttrNotFound: // Probably can't happen. return ImmutableArray.Create(SystemCoreIdentity); case ErrorCode.ERR_BadAwaitArg_NeedSystem: Debug.Assert(false, "Roslyn no longer produces ERR_BadAwaitArg_NeedSystem"); break; } return default(ImmutableArray<AssemblyIdentity>); }
public static string GetPublicKeyToken(this AssemblyIdentity identity) { return(identity.PublicKeyToken.Aggregate("", (s, b) => s += b.ToString("x2"))); }