System.TypeLoadException error when executing a dll created via c# .net standard library

i compiled an open source code (from github) into a dll, the code changes an executable's icon and id like to use said code in my python project so i compiled it into a dll and loaded it via using clr (a lib which lets you load c#-compiled dll's into python) it loads in without error and gets improrted fine, the issue is upon excuting a method of the class inside the dll i get the exception
System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.GCHandle' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at IconInject.IconInjector.IconFile.FromFile(String filename)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName, UInt32 iconGroupID, UInt32 iconBaseID)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName)
System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.GCHandle' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at IconInject.IconInjector.IconFile.FromFile(String filename)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName, UInt32 iconGroupID, UInt32 iconBaseID)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName)
i compiled and loaded multiple sample dlls (simple ones) and they ran fine without issue, from what i gather its an import issue of GCHandle which is (if i understand correctly) unmanged memory allocator im very very newbie with c# and program mostly in python, but i like how fast and verstile c# while prefering the syntax and ease of use of python, hence i use c#- compiled dll's with python, mostly without issues, any help will be appricated!
6 Replies
SpickeyCactus
SpickeyCactus5mo ago
i mostly understand what each part of the code does, but no where near a proper c# programmer
canton7
canton75mo ago
Is there an InnerException on the TypeLoadException?
SpickeyCactus
SpickeyCactus5mo ago
no, this is the entire traceback
Traceback (most recent call last):
File "C:\path\to\python_project\change_icon.py", line 12, in <module>
IconInject.IconInjector.InjectIcon(r"C:\path\to\rtgr.exe", r"C:\path\ie.ico")
System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.GCHandle' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at IconInject.IconInjector.IconFile.FromFile(String filename)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName, UInt32 iconGroupID, UInt32 iconBaseID)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName)
Traceback (most recent call last):
File "C:\path\to\python_project\change_icon.py", line 12, in <module>
IconInject.IconInjector.InjectIcon(r"C:\path\to\rtgr.exe", r"C:\path\ie.ico")
System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.GCHandle' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at IconInject.IconInjector.IconFile.FromFile(String filename)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName, UInt32 iconGroupID, UInt32 iconBaseID)
at IconInject.IconInjector.InjectIcon(String exeFileName, String iconFileName)
canton7
canton75mo ago
My guess would be that the DLL targets a different .NET version to the one it was loaded into, but I've no idea how your python thingy works
SpickeyCactus
SpickeyCactus5mo ago
will check into this, thanks!