views:

756

answers:

5

I've a working XML Web service written in ASP.Net. Now I need to reference certain assemblies lying in a specific folder e.g. c:\NotMyCode
I do not want to copy/duplicate zillions of dlls in that folder into my bin folder.

I tried to keep the CopyLocal=false for the assemblies referred in the Web Service. That ended up in a FileNotFound exception for the assembly. When I switch to CopyLocal=true, the referenced DLLs are copied over to the bin folder.. and it works.

So my question here is: How do I reference assemblies that do not lie in my bin folder or a subfolder beneath it ? Do I need to change some security policy files somewhere? I think I'm not the first person to ever want to do something like this.. so I'm assuming someone has already solved this problem.

(I've tried impersonating an admin user in the IIS ASP.net configuration panel, but that didnt work either.)

Thanks for reading...

Update: Can't install it in the GAC either. To give an analogy, this web service is giving a simplified view to a third party app e.g. Starteam. I can't (shouldn't have to.. don't want to..) copy all the binaries in that folder to the bin folder or install it into the GAC

A: 

You could always put your referenced assemblies in the GAC, then the location would not matter. You can install the component by dragging it into the GAC (C:\windows\assembly) or running GACUtil.exe.

This article may help. It describes the "Best Practices for Assembly Loading."

At first I thought you could used the <probing privatePath="bin\debug"/> element in the runtime/assemblyBinding in the web.config, but the probing will only allow you to specify subdirectories under the root location.

Mike Ohlsen
A: 
<runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing publicPath="C:\MyFolder" />
      <dependentAssembly>
       <assemblyIdentity name="MyAssembly" />
      </dependentAssembly>
     </assemblyBinding>
</runtime>

Now the runtime knows where to look if it doesn't find your referenced assembly in the bin directory, GAC, etc.

Ivan Zlatanov
i dont think this will work. the probe can only see subdirectories in under teh root application path.
Mike Ohlsen
A: 

You can put in GAC and access it from there.

Bhaskar
please read the end of my question..
Gishu
A: 

I think you can reference specific assembly paths in code as well.

AppDomain.CurrentDomain.AppendPrivatePath("C:\\NotMyCode");

Doing that in your Global.asax Application_Start should do the trick.

davewasthere
AppendPrivatePath is obsolete, according to MSDN: http://msdn.microsoft.com/en-us/library/system.appdomain.appendprivatepath.aspx
Vinay Sajip
That must have been in 3.5.. Am still heavily 2.0 unfortunately. PrivateBinPath then.... Same same...
davewasthere
+2  A: 
Vinay Sajip
+1 for sneakiness.. didn't know about linkd. It managed to fool Windows explorer but not ASP.Net. ASP.net copies the binaries to a temporary location from where it is executed. What is strange is that the temp location shows these files - however FusionLogVw does not show an entry for failed assembly resolution. But the server responds with a FileNotFound as usual...
Gishu
That's a bummer :-(
Vinay Sajip