0

We have a .Net application that successfully "load" .dll libraries from a specific folder in Windows Operative System. The .Net framework we have been using so far is 4.6. All the .dll libraries that the application loads were compiled in x86. The following code is an excerpt of how we are loading the libraries and getting their types:

1. try{
2.   AssemblyFileDescriptor assemblyFile = new AssemblyFileDescriptor(assemblyPath);
3.  var assm = Assembly.LoadFrom(assemblyPath);
4.  var types = assm.GetExportedTypes();
5.  ...
6. }catch (Exception e) {
7.  ...} 

The libraries in a specific folder, let's say

C:\Program Files (x86)\FOLDER

, are loading to the variable assm without any exception. The problem occurs when we migrated our .Net "stand alone" application to a website application with a Web.config file. In the website application, the load function fails when getting the types. Then the 4th line throws the exception. We have been using the ISS Express.

We have already tried:

  1. Using a different Load function such as "UnsafeLoadFrom".
  2. Re-compiling all the .dll libraries in x86 and x64.
  3. Setting up different configurations for the Web.Config file such as including <trust level="Full" /> or <loadFromRemoteSources enabled="true" />.
  4. Debugging the loading function of each library. Some of them can load successfully, but there are others that throw a Loading Exception.
  5. Setting in the ISS Express "True" the variable "Enable 32-bit applications".

The specific error states "System.Reflection.ReflectionTypeLoadException":

Image

Any idea of how tackling this issue? Let me know if you need further information.

Sean Werkema
  • 5,810
  • 2
  • 38
  • 42

2 Answers2

0

I'm guessing you're running this under IIS, and IIS usually runs as a different user than you (usually IUSR), and usually has limited permissions. Converting a standalone program to an ASP.NET program changes a lot of things in subtle ways. I'd check to make sure you aren't running into a file-permission issue because IIS is a restricted user.

Also, as others pointed out, you should probably provide the exception details (at least its typename and message) so people don't have to guess at it.

Sean Werkema
  • 5,810
  • 2
  • 38
  • 42
  • We are running the app under ISS Express. Should we configure an independent ISS for testing?. The specific error is "System.Reflection.ReflectionTypeLoadException". The description states that the variable _assm_ started an "System.TypeLoadException". – David Nader Mar 14 '17 at 16:17
  • Hmm, no, IIS express runs as your user ( http://stackoverflow.com/questions/8446359/what-account-does-iis-express-run-under ). So it's probably not a permissions issue under that. I wouldn't recommend switching to full IIS until you sort this out. – Sean Werkema Mar 14 '17 at 16:22
  • Actually, come to think on it: Since IIS Express runs as _you_, have you tried moving those files to a folder that _you_ own? `Program Files` is pretty special, and UAC and permissions can mess with anything in there. You might want to try moving those DLLs to a folder under your project just to be sure they're in a place the code can read from. – Sean Werkema Mar 14 '17 at 16:24
  • We have already tried to load the DLLs from the *Documents* folder and from the *Bin* folder of the project. The exception remains the same. – David Nader Mar 14 '17 at 17:17
  • Well, I guess you could try real IIS. That could open up another can of worms, but since IIS and IIS Express aren't really the same machinery under the hood, sometimes things will work in one that will not work in the other. (For example, my company's flagship application won't run _at all_ under IIS Express, for reasons too complicated to go into here; but the point is that they definitely aren't the same system.) – Sean Werkema Mar 14 '17 at 22:04
  • Thank you so much for your help. We found the solution; it was related to the .Net Framework Version of the libraries and their compatibility with CLR4. – David Nader Mar 16 '17 at 20:31
0

According to the answers of this question and several loading experiments that we had been performing in the website application. We observed a pattern related to the framework version that we used for compiling the DLLs and the ReflectionTypeLoadException. Some DLLs were compiled with framework 3.5, this version does not allow loading libraries in ISS with .Net CLR2. Then, we must rebuild all the DLLs and their dependencies with a higher version of the framework (.Net v4.0). Finally, we re-loaded the updated DLLs in ISS express with .NET CLR4. The DLLs were loaded without any exception.

Community
  • 1
  • 1