Created attachment 23187 [details]
If a ResolveEventHandler is installed while we are looking for the arguments of custom attributes, we may call ono_assembly_metadata_foreach_custom_attr on a dynamic assembly, which triggers an assertion:
* Assertion at custom-attrs.c:1947, condition `!image_is_dynamic (image)' not met
1. download and unzip the attached file.
2. run make
Some manner of exception
the assert from above.
The function mono_assembly_metadata_foreach_custom_attr is called by the loader to look for ReflectionAssemblyAttribute attributes. It did not expect to be called with a dynamic assembly (as the ResolveEventHandler in the example does).
The solution is to check if the assembly is dynamic and if so go through its attributes using the normal MonoCustomAttrInfo* APIs. (I think this is okay to do because the dynamic assembly will have all of its MonoClasses existing already so it won't trigger another loader event.)
Hm. Interestingly, .NET Framework (and .NET Core 2.0) seems to ignore ReferenceAssemblyAttribute when it's set on an AssemblyBuilder and happily runs the generated assembly. So we should really do two things:
1. (bugfix) Not even bother checking for the ReferenceAssemblyAttribute when the assembly is dynamic.
2. (feature enhancement) Teach mono_assembly_metadata_foreach_custom_attr to iterate over dynamic assemblies.
Fixed on mono master https://github.com/mono/mono/commit/6559b16c146623f16402c3504c19f94e0c0f4d7c
Fixed on mono 2017-06 https://github.com/mono/mono/commit/04419ee95be98831e0cad46135f38cd705630486