0

I am building a REST server (?) by using ASP .NET and Web API and IIS. Everything went fine until I added a reference to a 3rdparty .dll. Then I get the runtime error: Could not load file or assembly 'xx.DLL' or one of its dependencies.

I have added all relevant directories (I think) to the "Reference Paths" page in Visual Studio. Are these paths used at runtime? Or are there some other file/setting in the project I have to edit?

Also when I search for the offending .dll I find a copy: C:\Users\Andy\AppData\Local\Temp\Temporary ASP.NET Files\root\24c08d5b\dcd0af52\assembly\dl3\58d7d48b\005afae1_ece9d201\xx.DLL

Why does ASP .NET copy my .dlls? Can I stop it from doing this? And why is there only one .dll in this directory?

Andy
  • 3,251
  • 4
  • 32
  • 53
  • Possible duplicate of [What is the "Temporary ASP.NET Files" folder for?](https://stackoverflow.com/questions/450831/what-is-the-temporary-asp-net-files-folder-for) – gunr2171 Nov 09 '18 at 14:55
  • Do you get any compile time error while building the project? From where did you add the DLL reference, does DLL on your computer? – Azaz ul Haq Nov 09 '18 at 15:19

1 Answers1

1

Reference Path

Reference Paths in VS is only used by Visual Studio locally. Think of it as a way to override hint path of your references but just locally. AKA - It won't help you once you want to run the code outside of VS (deployed to a server for example).

If you are trying to reference 3rd party dlls for consumption in your project you will want to reference them directly in your application via the add reference dialog.

GAC vs Not Gac'd and Copy Local Property

If the 3rd party dlls are installed on the computer(s) into the GAC then you as long as all machines have it installed you should be good. Just add the reference and set the copy local property to false (click on your reference in VS and look at it's properties tab).

If they aren't installed into the GAC then copy local true is needed.

The results you are seeing with the temporary asp.net files location is dependent upon your references having the copy local property of your references equal to true.

Copy Local = true means: I need this DLL in order for my application to run properly and I know this DLL is not in the GAC so please copy it when you compile.

Copy Local = false means: I need this DLL but it is in the GAC on my server/deploy locations and as such I don't need to copy it. The .Net runtime will find it for me (in the GAC).

Bonus

If these 3rd party DLL's have a nuget package, use that.

If they don't consider:

A generally accepted way of handling the referencing/usage of 3rd party dlls not in the GAC is to create a lib folder in the root of your project solution, add the needed dlls into that folder and then reference those files and have the reference copy local to true so that the files on build are copied to ensure that they are always with your compiled output.

The lib folder is then source controlled along with your code to ensure the version of the dll's needed follow with the code.

Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
  • I have roughly 100 3rd party .dll's in a folder. I add 3 of these as references to my project (copy local = true). These 3 in turn depend on other .dlls in the folder. Which I do not know. Do i have to add reference to all 100 .dlls in the project or is there some way I can tell ASP .NET to look inside my directory? – Andy Nov 12 '18 at 09:49
  • 1
    Well, I think you are a bit stuck in that you'll have to bring them all in with copy local OR GAC them yourself if you can Strong Name them but I'm not sure that is a good idea since these DLLs are not under your control. This is a perfect reason for nuget packages. It would take care of this for you. Try and push your 3rd party to package them. In the meantime, reference every one of the dlls with copy local. – Kevin LaBranche Nov 13 '18 at 14:29