C
C#2y 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
ascpixiOP2y 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
reflectronic2y ago
if i may, i would suggest using TerraFX.Introp.Windows instead of Vortice it does not do any reflection
ascpixi
ascpixiOP2y ago
i looked into it but Vortice simplified a lot of things
ascpixi
ascpixiOP2y ago
like i'm not sure what to do here
ascpixi
ascpixiOP2y ago
(i mean what's the "correct" way to get IDXGIFactory)
reflectronic
reflectronic2y 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
ascpixiOP2y ago
thats kinda scary but thanks! :p
reflectronic
reflectronic2y 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
ascpixiOP2y ago
uuuum i don't have an As method ^^'>
reflectronic
reflectronic2y ago
oh
ascpixi
ascpixiOP2y ago
i'm porting this from vortice code so the types remained the same
ascpixi
ascpixiOP2y ago
(for context)
reflectronic
reflectronic2y ago
oh, i see yeah, it's going to be painful
ascpixi
ascpixiOP2y 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
reflectronic2y ago
is there a reason you want to use IlcDisableReflection
ascpixi
ascpixiOP2y 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
reflectronic2y 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
ascpixiOP2y 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
reflectronic2y 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
ascpixiOP2y 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
reflectronic2y ago
you can probably try to debug why the reflection metadata is being preserved
ascpixi
ascpixiOP2y ago
i mean stuff that wasnt used wasnt included so that was working correctly
reflectronic
reflectronic2y ago
stuff that is used but not by reflection should not be included
ascpixi
ascpixiOP2y ago
it was just that it included names of internal classes so i was a bit spooked ;P
reflectronic
reflectronic2y 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
ascpixiOP2y ago
uuuuuuuuuhhh weeelll lets just say i forgot to do that because i disabled reflection and that took care of it XD
reflectronic
reflectronic2y 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
ascpixiOP2y ago
i see theres a lot of fancy properties like that
ascpixi
ascpixiOP2y ago
is there documentation that lists them?
reflectronic
reflectronic2y 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
ascpixiOP2y ago
yeye i saw that but i couldnt find any docs about IlcScanReflection for example IlcGenerateStackData was on the optimization page
reflectronic
reflectronic2y 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
ascpixiOP2y ago
oh, i see...
reflectronic
reflectronic2y ago
i mean. it breaks them because they use reflection. it's just that you wouldn't expect it
ascpixi
ascpixiOP2y 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
reflectronic2y 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
ascpixiOP2y 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
reflectronic2y ago
it won't burn your computer so i suppose there is no harm in trying it
ascpixi
ascpixiOP2y ago
(it still would be nicer to have a markdown file listing it just sayiinggggg ⚆_⚆)
Accord
Accord2y 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.
Want results from more Discord servers?
Add your server