C
C#14mo ago
ascpixi

❔ ✅ Unhandled Exception: EETypeRva:0x0017C798: Reflection_Disabled on startup?

Hi all! I'm trying to build an AOT-compiled project with reflection disabled, using <IlcDisableReflection>true</IlcDisableReflection>. However, I'm getting the following exception on startup:
Unhandled Exception: EETypeRva:0x0017C798: Reflection_Disabled
at Internal.Reflection.RuntimeTypeInfo.get_GUID() + 0x33
at SharpGenModuleInitializer.Initialize() + 0x3c9
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x39
at [PROJECT NAME]!<BaseAddress>+0x128c3e
Unhandled Exception: EETypeRva:0x0017C798: Reflection_Disabled
at Internal.Reflection.RuntimeTypeInfo.get_GUID() + 0x33
at SharpGenModuleInitializer.Initialize() + 0x3c9
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunInitializers(TypeManagerHandle, ReadyToRunSectionType) + 0x45
at Internal.Runtime.CompilerHelpers.StartupCodeHelpers.RunModuleInitializers() + 0x39
at [PROJECT NAME]!<BaseAddress>+0x128c3e
The project compiles fine without IlcDisableReflection. This exception only appeared when I added GUI functionality to my project with the help of ImGui.NET. The NuGet packages I'm using are:
ImGui.NET
SixLabors.ImageSharp
Vortice.D3DCompiler
Vortice.Direct3D11
Vortice.DXGI
ImGui.NET
SixLabors.ImageSharp
Vortice.D3DCompiler
Vortice.Direct3D11
Vortice.DXGI
Can anyone help me out? Thanks in advance! catlove
40 Replies
ascpixi
ascpixi14mo ago
GitHub
SharpGenTools/SharpGenModuleGenerator.GenerateModule.cs at 461a942d...
Accurate and high performance C++ interop code generator for C#. - SharpGenTools/SharpGenModuleGenerator.GenerateModule.cs at 461a942deb05c6f82489d11eccfb3c05b2d85def · SharpGenTools/SharpGenTools
reflectronic
reflectronic14mo ago
if i may, i would suggest using TerraFX.Introp.Windows instead of Vortice it does not do any reflection
ascpixi
ascpixi14mo ago
i looked into it but Vortice simplified a lot of things
ascpixi
ascpixi14mo ago
like i'm not sure what to do here
ascpixi
ascpixi14mo ago
(i mean what's the "correct" way to get IDXGIFactory)
reflectronic
reflectronic14mo ago
using ComPtr<IDXGIDevice> dxgiDevice = default;
HRESULT hr = device.QueryInterface(Windows.__uuidof<IDXGIDevice>(), (void**)dxgiDevice.GetAddressOf());
using ComPtr<IDXGIDevice> dxgiDevice = default;
HRESULT hr = device.QueryInterface(Windows.__uuidof<IDXGIDevice>(), (void**)dxgiDevice.GetAddressOf());
ascpixi
ascpixi14mo ago
thats kinda scary but thanks! :p
reflectronic
reflectronic14mo ago
or, rather using var dxgiDevice = device.As<IDXGIDevice>() sorry, i forgot about that uh
using ComPtr<IDXGIDevice> dxgiDevice = default;
HRESULT hr = device.As(&dxgiDevice);
using ComPtr<IDXGIDevice> dxgiDevice = default;
HRESULT hr = device.As(&dxgiDevice);
that's what i meant it has been a while
ascpixi
ascpixi14mo ago
uuuum i don't have an As method ^^'>
reflectronic
reflectronic14mo ago
oh
ascpixi
ascpixi14mo ago
i'm porting this from vortice code so the types remained the same
ascpixi
ascpixi14mo ago
(for context)
reflectronic
reflectronic14mo ago
oh, i see yeah, it's going to be painful
ascpixi
ascpixi14mo ago
:( i was thinking of making an IL weaving shim that just replaces all System.Type.GUID accesses with a GUID that's generated using the runtime type handle lol
reflectronic
reflectronic14mo ago
is there a reason you want to use IlcDisableReflection
ascpixi
ascpixi14mo ago
but then i noticed it has so much more reflection code scattered everywhere mainly to protect the source code, i guess w/ a hex editor i noticed that all type names and stuff like that are included in the executable (which is expected behavior of course) it would be nice to have something like "partial reflection" XD maybe something like a [DontReflect] attribute so i could mark my codebase as "please dont include type info of this assembly ty <3" i guess i could use an obfuscator..... but i figured that i'd try doing it without reflection first
reflectronic
reflectronic14mo ago
to be clear, the NativeAOT compiler only keeps required reflection metadata so if it's in the executable it's because there are codepaths that will use it
ascpixi
ascpixi14mo ago
sooo if i just obfuscate the names of all members + types + namespaces, that would be enough to protect something from reverse engineering? (i know that with enough patience everything can be reverse engineered but i just want to dismay casual onlookers i guess lol)
reflectronic
reflectronic14mo ago
the casual onlookers will already be dismayed because there is no IL and the native code will be incomprehensible in any binary reverse engineering toolkit you can find, becuase none of them are tuned for RyuJIT. which will dismay almost all of the less casual ones i mean. renaming everything is free and easy. so, sure, why not but you are already reaching the tail end of protections here
ascpixi
ascpixi14mo ago
yeah i already have IL weaving set-up for string encryption so i think i can easily plug member name obfuscation in there i guess i was a bit paranoid about reflection giving away a bit too much info lol alright, thanks for the help!!
reflectronic
reflectronic14mo ago
you can probably try to debug why the reflection metadata is being preserved
ascpixi
ascpixi14mo ago
i mean stuff that wasnt used wasnt included so that was working correctly
reflectronic
reflectronic14mo ago
stuff that is used but not by reflection should not be included
ascpixi
ascpixi14mo ago
it was just that it included names of internal classes so i was a bit spooked ;P
reflectronic
reflectronic14mo ago
the compiler will remove the name and metadata for a method while keeping its native code if it sees that the method is never accessed with reflection. (same for classes and so on) so if it's there, something is keeping it there. which means reflection-free was broken anyway (and, i know this is a bit of a dumb question, but... are you sure you turned off stack trace metadata as well)
ascpixi
ascpixi14mo ago
uuuuuuuuuhhh weeelll lets just say i forgot to do that because i disabled reflection and that took care of it XD
reflectronic
reflectronic14mo ago
you may want to try with <IlcGenerateStackTraceData>false</IlcGenerateStackTraceData> and see how many strings are there it is harmless, your exception stack traces will just be mostly offsets instead of names
ascpixi
ascpixi14mo ago
i see theres a lot of fancy properties like that
ascpixi
ascpixi14mo ago
is there documentation that lists them?
reflectronic
reflectronic14mo ago
everything that begins with Ilc is not "officially" supported but there is some "internal" documentation about the flags here https://github.com/dotnet/runtime/tree/c32bee11a457151e5c400107ababed54dcd70438/src/coreclr/nativeaot/docs
ascpixi
ascpixi14mo ago
yeye i saw that but i couldnt find any docs about IlcScanReflection for example IlcGenerateStackData was on the optimization page
reflectronic
reflectronic14mo ago
the reflection-free mode is sort of a dud. it breaks all sorts of code that is not even related to reflection, like HttpClient, Process.Start, some crypto stuff, there's more. if you can get it to work without using it then your day will be much brighter and you will be able to use Vortice
ascpixi
ascpixi14mo ago
oh, i see...
reflectronic
reflectronic14mo ago
i mean. it breaks them because they use reflection. it's just that you wouldn't expect it
ascpixi
ascpixi14mo ago
yeah i've given up on reflection-free mode, it'll be less painful to use reflection rather than try to port all the DX code I have from Vortice to TerraFX lol
reflectronic
reflectronic14mo ago
honestly i would rather spend a day tweaking build properties than spending a day rewriting everything in TerraFX it's just painful, i would rather use C or C++ for these the documentation is the source code IlcScanReflection controls the thing that scans for reflection patterns (the thing that determines whether to keep reflection metadata for each member). i don't know what will happen if you set it to false
ascpixi
ascpixi14mo ago
eh i mean i'm used to reading the runtime docs at this point when i was writing my own bare metal runtime xd
reflectronic
reflectronic14mo ago
it won't burn your computer so i suppose there is no harm in trying it
ascpixi
ascpixi14mo ago
(it still would be nicer to have a markdown file listing it just sayiinggggg ⚆_⚆)
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.