-
Notifications
You must be signed in to change notification settings - Fork 128
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
Linker is warning for Assembly.GetType for hard-coded type #1884
Comments
Can you change this to: private static readonly Type ComObjectType = Type.GetType("System.__ComObject, System.Runtime"); It will be equivalent and illink models that API. Modeling assembly was scoped out for now because this is the only situation where it would work (both the assembly and the type in question need to be visible).
|
Should we tweak the error message or add a special version to include Type.GetType suggestion? |
Roughly, the same pattern is found here: public ComNativeDescriptorProxy()
{
Assembly assembly = Assembly.Load("System.Windows.Forms");
Type realComNativeDescriptor = assembly.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor", throwOnError: true);
_comNativeDescriptor = (TypeDescriptionProvider)Activator.CreateInstance(realComNativeDescriptor);
} Albeit, this is pointing to an Assembly and Type that is unknown when analyzing the runtimepack. |
See dotnet/corefx#36496 (comment) for why it was written this way, and not Type.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor, System.Windows.Forms");
@AaronRobinsonMSFT - is it OK if I change (If I change it, I'd like to test the change to make sure it works - can you tell me how to test it?) |
I'm not sure I understand the motivation:
Either of these will end up with a FileNotFoundException saying Dont cannot be found. What does the two liner help with? |
We now have a very detailed tracing of assembly loading failures: https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/collect-details |
My understanding is the scenario where the assembly can be found, but the Type can't be found. But even in the 1-liner case you get different exception types between the 2 error cases: |
@eerhardt I've tagged the appropriate owners for the scenario in the referenced PR. It looks fine to me and I think it should be okay. I've forwarded you an email about this area and how it impact WinForms. |
In dotnet/runtime we have https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs#L420
with a single usage of that field https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/DynamicDebuggerProxy.cs#L445 :
it seems that linker should be able to figure out what to do here but it warns instead:
cc: @eerhardt
The text was updated successfully, but these errors were encountered: