From 1c92e352b1d2d8c58b3f2957c399088d1653775a Mon Sep 17 00:00:00 2001 From: Jose Perez Rodriguez Date: Tue, 22 Sep 2015 17:01:45 -0700 Subject: [PATCH] Changing type forwards to be looped from the contract assembly instead of the seedtype. --- src/GenFacades/Program.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/GenFacades/Program.cs b/src/GenFacades/Program.cs index 2c7d57096f..36cfb81a00 100644 --- a/src/GenFacades/Program.cs +++ b/src/GenFacades/Program.cs @@ -417,7 +417,7 @@ public Assembly GenerateFacade(IAssembly contractAssembly, IAssemblyReference se continue; } - AddTypeForward(assembly, seedType); + AddTypeForward(assembly, seedType, contractAssembly); } if (error) @@ -475,7 +475,7 @@ private static void TraceDuplicateSeedTypeError(string docId, IReadOnlyList(); assembly.ExportedTypes.Add(alias); - // Recursively add forwarders only for the nested types that are accessible outside of the assembly. + INamedTypeDefinition contractType = contractAssembly.GetAllTypes().Where(t => t.FullName() == seedType.FullName()).FirstOrDefault(); + if (contractType == null) + throw new Exception("Type was not found in the contract."); + + // Recursively add forwarders for all the nested types specified in the contract assembly. // NOTE: Some design-time tools can resolve forwarded nested types with only the top-level forwarder, // but the runtime currently throws a TypeLoadException without explicit forwarders for the nested // types. - foreach (var nestedType in seedType.NestedTypes.OrderBy(t => t.Name.Value)) - if (nestedType.IsVisibleOutsideAssembly()) - AddTypeForward(assembly, nestedType); + foreach (var nestedType in contractType.NestedTypes.OrderBy(t => t.Name.Value)) + { + var seedNestedType = seedType.NestedTypes.Where(nt => nt.Name.Value == nestedType.Name.Value).FirstOrDefault(); + if (seedNestedType == null) + throw new Exception("Nested type found in the contract, but not on the seedType."); + AddTypeForward(assembly, seedNestedType, contractAssembly); + } } private void AddWin32VersionResource(string contractLocation, Assembly facade)