-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
TypeBuilder.CreateType doesn't work on Windows in a trimmed app due to BuiltInComInterop being disabled #55600
Comments
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr Issue DetailsDescriptionWhen trimming an app that uses Ref.Emit to generate a Type, it fails by default on Windows due to BuiltInComInterop being disabled. Using a recent .NET 6 SDK, <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
</Project> using System;
using System.Reflection;
using System.Reflection.Emit;
AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("GeneratedAssembly"), AssemblyBuilderAccess.Run);
ModuleBuilder module = assembly.DefineDynamicModule("GeneratedModule");
TypeBuilder genericType = module.DefineType("GeneratedType");
genericType.DefineField("_int", typeof(int), FieldAttributes.Private);
genericType.DefineProperty("Prop", PropertyAttributes.None, typeof(string), null);
Type generatedType = genericType.CreateType();
Console.WriteLine(generatedType);
Configuration
Regression?Yes, this worked before 6.0.0-preview5 because BuiltInComInterop wasn't disabled by default. We disable BuiltInComInterop by default starting in 6.0.0-preview5. cc @LakshanF @agocke @vitek-karas @sbomer
|
It seems like this is failing when preparing the cc @elinor-fung, @jkoritzinsky
|
I think we should wrap that block in a check for if built-in COM is enabled. |
Yeah. Probably also worth doing a search for all those wrapper classes / other similar checks in the runtime and seeing if they are already blocked or they need to be blocked. |
…in COM is disabled. Fixes dotnet#55600
…in COM is disabled. (#55756) * Disable array support for the COM variant wrapper classes when built-in COM is disabled. Fixes #55600 * Fix config call. * Fix one more location of wrapper class usage. * Fix method name. * Add trimming test. * Fix AV in IsArrayOfWrappers * Fix trimming test * Apply suggestions from code review Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Set Trim=true Co-authored-by: Elinor Fung <elfung@microsoft.com> Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Description
When trimming an app that uses Ref.Emit to generate a Type, it fails by default on Windows due to BuiltInComInterop being disabled.
Using a recent .NET 6 SDK,
dotnet publish
the following app:Configuration
.NET 6.0.0-preview5+
Windows
x64
yes
Regression?
Yes, this worked before 6.0.0-preview5 because BuiltInComInterop wasn't disabled by default. We disable BuiltInComInterop by default starting in 6.0.0-preview5.
cc @LakshanF @agocke @vitek-karas @sbomer
The text was updated successfully, but these errors were encountered: