Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LoadAssemblyFromFile Problem

 
Post new topic   Reply to topic    Infralution Support Forum Index -> .NET Encryptor Support
View previous topic :: View next topic  
Author Message
GeorgeVovos



Joined: 13 Feb 2018
Posts: 3

PostPosted: Tue Feb 13, 2018 12:34 pm    Post subject: LoadAssemblyFromFile Problem Reply with quote

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
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 4826

PostPosted: Sat Feb 17, 2018 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
GeorgeVovos



Joined: 13 Feb 2018
Posts: 3

PostPosted: Mon Feb 19, 2018 11:32 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> .NET Encryptor Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group