You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attempt to use of dynamically created type in the attribute leads to exception #95829
I dynamically create the type with method that have an attribute. Attribute(not dynamic itself) have a parameter of type System.Type. As parameter I use another dynamically created type. That is lead to exception whenever I try to get that attribute later using System.Reflection.
Reproduction Steps
Here, the simple console project that reproduces that problem. Extract the archive, build the project, run ConsoleApp2 application. There will be exception at the last line of method Main(). ReproductionSolution.zip
Expected behavior
It must be allowed to use dynamically created types in the attributes of dynamically created types.
Actual behavior
While dynamic generation of attributed type by specified method in itself does not lead to exception, the later attempt to read attributes from that type with help of Syste.Reflection spawns it (System.IO.FileNotFound).
Regression?
The same functionality works OK under .NET Framework
Known Workarounds
I don't know any workaround.
Attempt to help .NET find the dynamic assembly through Resolving event from AssemblyLoadContext leads to unmanaged exception inside the module.
Configuration
.NET 6
Windows 10
x64
Other information
No response
Activity
ghost added
needs-area-labelAn area label is needed to ensure this gets routed to the appropriate area owners
changed the title [-]Attempt to use of dynamically creates type in the attribute leads to exception[/-][+]Attempt to use of dynamically created type in the attribute leads to exception[/+]on Dec 10, 2023
Attempt to help .NET find the dynamic assembly through Resolving event from AssemblyLoadContext leads to unmanaged exception inside the module.
@elinor-fung could you take a look? The repro is attached in the issue description
AssemblyLoadContext.Resolving does not allow returning dynamically-emitted assemblies (as it affects how they get cached for the ALC). AppDomain.AssemblyResolve should allow it.
Works ok under .NET Framework, if before that line with exception you insert event handler for AppDomain.CurrentDomain.AssemblyResolve+=(sender,resolveArgs)=>assemblyBuilder;15 февр. 2024 г., в 22:05, Buyaa Namnan ***@***.***> написал(а):
Regression?
The same functionality works OK under .NET Framework
@SnarkOrBoojum2 the same example actually throws the same exception, not sure what I missed ...
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
ghost added
needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
With the event handler it works for me on .NET Core, but I believe you should not unconditionally return the assembllyBuillder, only when the unresolved assembly matches with the assembllyBuillder:
Yes, it was my mistake/ I have the same code for .NET Framework(with name
check and all) but thinking that under .NET new functionality must be used
and I tried
пт, 16 февр. 2024 г. в 00:49, Buyaa Namnan ***@***.***>:
Yes it was my mistake, i have the same code under .NET Framework with name
check and all, but thinking that under .NET - new functionality must be
used and I tried
AssemblyLoadContext.Default.Resolving+=(AssemblyLoadContext context,
AssemblyName assemblyName) =>
assemblyName.FullName == _assemblyBuilder.FullName ? _assemblyBuilder :
null;
But this doesnt not work(engine exception)
пт, 16 февр. 2024 г. в 00:49, Buyaa Namnan ***@***.***>:
We don't allow returning a dynamically emitted assembly from AssemblyLoadContext.Resolving, so the error is expected. In .NET 7 and later, this should come through more clearly:
Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'DynamicAssemblyExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. An operation is not legal in the current state. (0x80131509)
File name: 'DynamicAssemblyExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
---> System.InvalidOperationException: Dynamically emitted assemblies are unsupported during host-based resolution.
Whereas it looks like .NET 6 just reported internal error.
Fixed!
The solution with resolving assemblies through AppDomain.AssemblyResolve is
completely acceptable. If only this functionality (with AppDomain) will
not become obsolete in the future
пт, 16 февр. 2024 г. в 19:14, Elinor Fung ***@***.***>:
But this doesnt not work(engine exception)
We don't allow returning a dynamically emitted assembly from
AssemblyLoadContext.Resolving, so the error is expected. In .NET 7 and
later, this should come through more clearly:
Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'DynamicAssemblyExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. An operation is not legal in the current state. (0x80131509)
File name: 'DynamicAssemblyExample, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
---> System.InvalidOperationException: Dynamically emitted assemblies are unsupported during host-based resolution.
Whereas it looks like .NET 6 just reported internal error.
—
Reply to this email directly, view it on GitHub
<#95829 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AYWMQH6HAMJZAA5XWBUJOW3YT6AXDAVCNFSM6AAAAABAOAWWBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYG43TGMJWGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
Activity
[-]Attempt to use of dynamically creates type in the attribute leads to exception[/-][+]Attempt to use of dynamically created type in the attribute leads to exception[/+]buyaa-n commentedon Feb 14, 2024
@elinor-fung could you take a look? The repro is attached in the issue description
buyaa-n commentedon Feb 15, 2024
@SnarkOrBoojum2 the same example actually throws the same exception, not sure what I missed ...
elinor-fung commentedon Feb 15, 2024
AssemblyLoadContext.Resolvingdoes not allow returning dynamically-emitted assemblies (as it affects how they get cached for the ALC).AppDomain.AssemblyResolveshould allow it.SnarkOrBoojum2 commentedon Feb 15, 2024
buyaa-n commentedon Feb 15, 2024
With the event handler it works for me on .NET Core, but I believe you should not unconditionally return the
assembllyBuillder, only when the unresolved assembly matches with theassembllyBuillder:SnarkOrBoojum2 commentedon Feb 16, 2024
SnarkOrBoojum2 commentedon Feb 16, 2024
elinor-fung commentedon Feb 16, 2024
We don't allow returning a dynamically emitted assembly from
AssemblyLoadContext.Resolving, so the error is expected. In .NET 7 and later, this should come through more clearly:Whereas it looks like .NET 6 just reported internal error.
SnarkOrBoojum2 commentedon Feb 16, 2024