Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable array support for the COM variant wrapper classes when built-in COM is disabled. #55756

Merged
merged 10 commits into from
Jul 18, 2021
4 changes: 4 additions & 0 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<_ExtraTrimmerArgs>{ExtraTrimmerArgs} $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
</PropertyGroup>

<ItemGroup>
{RuntimeHostConfigurationOptions}
</ItemGroup>

<ItemGroup>
{AdditionalProjectReferences}
</ItemGroup>
Expand Down
14 changes: 13 additions & 1 deletion eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<_projectDir>%(TestConsoleApps.ProjectDir)\</_projectDir>
<_projectFile>%(TestConsoleApps.ProjectFile)</_projectFile>
<_projectSourceFile>%(TestConsoleApps.ProjectCompileItems)</_projectSourceFile>
<_extraTrimmerArgs>%(TestConsoleApps.ExtraTrimmerArgs)</_extraTrimmerArgs>
</PropertyGroup>

<ItemGroup Condition="'$(AdditionalProjectReferences)' != ''">
Expand All @@ -68,6 +69,16 @@
<_additionalProjectSourceFiles Include="%(TestConsoleApps.AdditionalSourceFiles)" />
</ItemGroup>

<ItemGroup>
<_switchesAsItems Include="%(TestConsoleApps.DisabledFeatureSwitches)" Value="false" />
<_switchesAsItems Include="%(TestConsoleApps.EnabledFeatureSwitches)" Value="true" />
</ItemGroup>

<PropertyGroup>
<_extraTrimmerArgs>$(_extraTrimmerArgs) @(_switchesAsItems->'--feature %(Identity) %(Value)', ' ')</_extraTrimmerArgs>
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
<_runtimeHostConfigruationOptionsString>@(_switchesAsItems->'&lt;RuntimeHostConfigurationOption Include=&quot;%(Identity)&quot; Value=&quot;%(Value)&quot; /&gt;', '%0a ')</_runtimeHostConfigruationOptionsString>
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
</PropertyGroup>

<MakeDir Directories="$(_projectDir)" />
<WriteLinesToFile File="$(_projectFile)"
Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)')
Expand All @@ -78,7 +89,8 @@
.Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)')
.Replace('{UseMonoRuntime}','$(UseMonoRuntime)')
.Replace('{MicrosoftNETILLinkTasksVersion}', '$(MicrosoftNETILLinkTasksVersion)')
.Replace('{ExtraTrimmerArgs}', '%(TestConsoleApps.ExtraTrimmerArgs)')
.Replace('{ExtraTrimmerArgs}', '$(_extraTrimmerArgs)')
.Replace('{RuntimeHostConfigurationOptions}', '$(_runtimeHostConfigruationOptionsString)')
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
.Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)')
.Replace('{RepositoryEngineeringDir}', '$(RepositoryEngineeringDir)')
.Replace('{MonoAOTCompilerDir}', '$(MonoAOTCompilerDir)')
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/vm/olevariant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4851,7 +4851,7 @@ void OleVariant::TransposeArrayData(BYTE *pDestData, BYTE *pSrcData, SIZE_T dwNu
}
}

BOOL OleVariant::IsArrayOfWrappers(BASEARRAYREF *pArray, BOOL *pbOfInterfaceWrappers)
BOOL OleVariant::IsArrayOfWrappers(_In_ BASEARRAYREF *pArray, _Out_opt_ BOOL *pbOfInterfaceWrappers)
{
CONTRACTL
{
Expand Down Expand Up @@ -4892,7 +4892,9 @@ BOOL OleVariant::IsArrayOfWrappers(BASEARRAYREF *pArray, BOOL *pbOfInterfaceWrap
}
}

*pbOfInterfaceWrappers = FALSE;
if (pbOfInterfaceWrappers)
*pbOfInterfaceWrappers = FALSE;

return FALSE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ExtraTrimmerArgs>--feature System.Resources.UseSystemResourceKeys true</ExtraTrimmerArgs>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="TypeBuilderComDisabled.cs">
<ExtraTrimmerArgs>--feature System.Runtime.InteropServices.BuiltInComInterop.IsSupported false</ExtraTrimmerArgs>
<DisabledFeatureSwitches>System.Runtime.InteropServices.BuiltInComInterop.IsSupported</DisabledFeatureSwitches>
</TestConsoleAppSourceFiles>
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@

AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("GeneratedAssembly"), AssemblyBuilderAccess.Run);
ModuleBuilder module = assembly.DefineDynamicModule("GeneratedModule");
TypeBuilder genericType = module.DefineType("GeneratedType");

string typeName = "GeneratedType";
TypeBuilder genericType = module.DefineType(typeName);
genericType.DefineField("_int", typeof(int), FieldAttributes.Private);
genericType.DefineProperty("Prop", PropertyAttributes.None, typeof(string), null);

Type generatedType = genericType.CreateType();
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
if (generatedType.Name != typeName)
{
Console.WriteLine($"Unexpected name for generated type. Expected: {typeName}, Actual: {generatedType.Name}");
return -1;
}

object obj = Activator.CreateInstance(generatedType);
string objAsString = obj.ToString();
if (objAsString != typeName)
{
Console.WriteLine($"Unexpected result of ToString() for instance of generated type. Expected: {typeName}, Actual: {objAsString}");
return -2;
}

return 100;