View previous topic :: View next topic |
Author |
Message |
GeorgeVovos
Joined: 13 Feb 2018 Posts: 3
|
Posted: Tue Feb 13, 2018 12:34 pm Post subject: LoadAssemblyFromFile Problem |
|
|
Hi
I'm trying to figure out if NET encryptor supports the following scenario.
I have an exe that references a dll.
Both are encrypted successfully.
In my Bootstrap app I only want to use the encrypted exe as an embedded resource.
I want the encrypted dll to be loaded dynamically (So that I can update my lib without redeploying everything)
I thought that LoadAssemblyFromFile would be the answer but I haven't managed to make it work.
All I'm doing is calling LoadAssemblyFromFile before ExecuteAssembly
Code: | AssemblyLoaderx86.AssemblyLoader.LoadAssemblyFromFile("SomePath\MyLib.enc");
AssemblyLoaderx86.AssemblyLoader.ExecuteAssembly(RESOURCE_PREFIX, assemblyName); |
But I get an error that my dll could not be loaded.
Am I doing anything wrong?
Is LoadAssemblyFromFile loading the assembly on the current AppDomain?
Should I use the returned object from LoadAssemblyFromFile?
It seems to be loaded correclty because I can create types defined in it using reflection.
If I embed the enc file everything works fine.
I could upload a sample project but probably I don't have to,the scenario is quite simple
Thanks |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Feb 17, 2018 9:31 am Post subject: |
|
|
The LoadAssemblyFromFile method wasn't really designed to be used for the purpose you want. It was designed so you could load the assembly and then execute methods by reflection.
.NET Encryptor implements a CurrentDomain.AssemblyResolve event handler which handles attempts to find missing assemblies and looks in the entry assemblies resources for encrypted assemblies matching the required assembly. It then decrypts, loads and resolves that assembly. This AssemblyResolve handler does not however resolve assemblies that you have loaded yourself using LoadAssemblyFromFile. You could probably work around this issue however by implementing your own AppDomain::CurrentDomain.AssemblyResolve handler and returning your loaded assembly when required. _________________ Infralution Support |
|
Back to top |
|
|
GeorgeVovos
Joined: 13 Feb 2018 Posts: 3
|
Posted: Mon Feb 19, 2018 11:32 am Post subject: |
|
|
Oh, I see.
I should have thought that myself.
Handling the CurrentDomain_AssemblyResolve event and using LoadAssemblyFromFile to return the correct Assembly solved my problem
Thanks |
|
Back to top |
|
|
|