title: Erro loading third party dll from Asp.Net Application
body: <p>the situation is quite complex ( and my english very basic) but let's try to explain:</p>
  
  <p>i'm developing a Asp.net web service calling a method from an external  dll.</p>
  
  <p>This external dll  calls some method from other .net dlls.</p>
  
  <p>So we have:</p>
  
  <pre><code>Asp.net WS ----&gt; External.dll ----&gt; other.NEt.Dll(---&gt; other .netdll)
  </code></pre>
  
  <p>You have to know that the external dll uses a path ( given by an initialize method) to resolve its internal reference.</p>
  
  <p>In conclusion i have a web application with an added reference to my External.dll and a fully trusted path ( c:\EXTERNAL ) full of all the .net dlls needed by external.dll.</p>
  
  <p>Looking around i've found this code to add to the application_START:</p>
  
  <pre><code>Dim path As String = String.Concat(System.Environment.GetEnvironmentVariable("PATH"), ";", "c:\EXTERNAL)
      System.Environment.SetEnvironmentVariable("PATH", path, EnvironmentVariableTarget.Machine)
  </code></pre>
  
  <p>this add my c:\EXTERNAL to global environment PATH.</p>
  
  <p>With this configuration running from the Visual Studio development server i get no error and it all works correctly.</p>
  
  <p>When i publish the application on my local IIS server it gives various errors:
  At first the result is something like:</p>
  
  <pre><code>Failure reading &lt;Myobject&gt; control of &lt;(static)&gt; type
  Unable to create &lt;myobject&gt; object (&lt;C:\(WRONGPATH)\needed.net.dll&gt; assembly)
  </code></pre>
  
  <p>To resolve this i've tried to add the needed .net dlls to the /bin of my application in wwwroot but the result is something like:</p>
  
  <pre><code>Failure reading &lt;MyType&gt; control of &lt;Myobject&gt; type
  Error returned by .NET Framework: 
  System.ArgumentException: Un oggetto di tipo 'ComNet.BaseControl.LoginDisplayLayout' non può essere convertito nel tipo 'ComNet.BaseControl.LoginDisplayLayout'.
     in System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
     in System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
     in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     in System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
     in System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
     in CDotNetType.bSetProperty(CDotNetType* , Object gcrObj, SByte* pszNom, CSLevel* pclPile, Int32 nDimension, Int32* pnTabDimension, STOperationDotNet* pstOperation)
  </code></pre>
  
  <p>this time it looks like it's loading the same dll but from different location causing conflicts.</p>
  
  <p>Now that's all. Its hard for me to explain this dll-hell but basically i would like to replicate whats happening when the application works well in the visual studio development server.
  I've also read that IIS does not resolve Added PATH without rebooting so i tried to add c:\external manually to the PATH and reboot but same errors appears.</p>
  
  <p>Thank you for reading, i hope someone can help.</p>
  
  <p>( sorry for grammar or spelling errors! ( i'm italian..))</p>
  
  <p>Nicola</p>