简体   繁体   中英

C# Web Api/ MVC.net not loading assemblies properly

I'm new to C# and .net in general, and I need to use it to work with the SDK for a major piece of software we use.

I can add the assemblies they tell me to add in a console application and everything works fine. When I try to add them to any web application (either MVC or WebAPI), I keep getting errors saying other assemblies are missing. Eventually I just added every assembly/reference (not sure the correct term for this, pretty much just .dll files) in the sdk folder and now it is working. This definitely cannot be the correct way to do this.

Is there something I am missing that allows assemblies/references to load other assemblies/references, or is something else the cause of my issue?

UPDATE:

The exceptions are usually something like this:

Could not load file or assembly 'Server, Version=1.5.1.0, Culture=neutral, PublicKeyToken=d11ef57bba4acf91' or one of its dependencies. The system cannot find the file specified. 

And it does not occur during build, only when the function is actually being called from the web application( in my case, since it's an api, when I visit the URL that returns my JSON data)

You can use a tool called "IL Disassembler" that is installed along with Visual Studio to see what other dependencies the SDK's Assembly depends on.

The install location may vary but mine is here... "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6 Tools\\ildasm.exe"

Drag and drop the SDK's assembly that you are using onto the tool and click the manifest field. A dialog will open with the other assemblies that you'll need to include.

在此输入图像描述

If your console application works but the web application does not then the exception should specify which assembly is missing.

Compare you console output directory with the output directory of you web build. Make sure the dll that is required is being deployed to the web directory you are running.

In visual studio with your web project find the assembly under references and select it. Make sure that the property "Copy Local" is set to TRUE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM