This question might be a little odd, but is there any specific way to import a C++ reference into an ASP.NET C# project?

The problem I am having is that VS is giving me the following error:

Error CS0246 The type or namespace name 'LicenseAdminApi' could not be found >(are you missing a using directive or an assembly reference?)...

This error only shows up within my Views and not in my Controller or any .cs code, The code within my views where I reference fields defined within the DLL also work without any issues. And the project compiles/builds and runs as expected without any issues.

LisenseAdminApi is a DLL also written by our company, just in a different department and it was developed in C++. It requires a Visual Studio 2015 C++("Microsoft Visual C++ 2015 Redistributable (x64) - 14.0.23918") runtime to run. I also had to change my project to run in x64 and use the x64 version of IIS. Without installing it I get the following error when I try and run the project:

Server Error in '/' Application.

Could not load file or assembly 'LicenseAdminApi.DLL' or one of its >dependencies. The specified module could not be found. Description: An unhandled exception occurred during the execution of the >current web request. Please review the stack trace for more information about >the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not load file or >assembly 'LicenseAdminApi.DLL' or one of its dependencies. The specified module >could not be found.

Similar to the error VS is giving me within the error list, which makes me think that it's not using the runtime within VS to read the DLL until the project is compiled. It's quite odd because like I said the project builds fine and runs without any issues once the runtime is installed, but the error in the error list is not going away and I need to sort it out as company policy is not to commit any code with errors.

Edit If I were to add the "@using LicenseAdminApi" to the view, it also gives me the same error in the error list. Not really sure what solution to try if any as I don't really know what's wrong to begin with.

The usage of the DLL is not the issue, I can call the methods I need and they work. The problem is that VS is giving me an error that seems to not exist when I build and run my project. Apart from the standard way of adding a reference which I assume everyone knows, is there anything I need to enable for VS to read the C++ DLL before compiling?

Edit 2

Within my Views/Web.config I have included my namespace like the following:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
    <add namespace="LicenseAdminApi" />

Which according to me should make the namespace available in my views, but it doesn't.

Once again the code is running fine and my project is building, it is only when I am not debugging that VS is telling me that my type/namespace could not be found. This also only occurs within my views, within my controllers I can reference the namespace without getting an error. Even though I do get the error in VS the code and my views all run perfectly when I debug

Please let me know if anyone needs more details, I have tried many different solutions including all the answers provided here

Thanks in advance

closed as off-topic by Bart van Ingen Schenau, gbjbaanb, Ixrec, gnat, MetaFight May 18 '16 at 13:40

  • This question does not appear to be about software engineering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.


The Visual Studio designer is a 32-bit application and therefore cannot load the 64 bit DLL. The reason it runs fine is that you are running as 64bit I.e. design and runtime are different architectures.

Generally when importing a native dll you write a wrapper class for the P/Invoke and then everything references that wrapper class (likely a static class). That would keep you from getting the designer errors.

You might have design time did in that class but you could always use #if statements to hide the 64 bit specific code and write place holder dummy 32bit items.

  • Hi @Eric, thanks for the helpful answer. I think this is what I was looking for but could not find. Do you happen to know of any good examples to deal with this? – Dave May 19 '16 at 5:28

LisenseAdminApi is a DLL also written by our company, just in a different department and it was developed in C++. It requires a Visual Studio 2015 C++("Microsoft Visual C++ 2015 Redistributable (x64) - 14.0.23918") runtime to run.

How about you go and ask the Developers who created the DLL how it's supposed to be used?

Or, (Shock; Horror) read the documentation that they provided with the DLL on how it should be used?

The use of the '14 runtime suggests it's a pretty recent build, so there's a good chance those Developers are still around ...

  • I have asked them and they said it should just be added into my references in my project which I have done. There is no documentation and I don't need any, usage of the DLL is not the issue. The issue is that VS is not reading my DLL correctly unless I compile/run my project – Dave May 18 '16 at 11:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.