Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing DLLImport even though there is a "using InteropServices"

Tags:

c#

dll

I have the following code:

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MapsApp.DB;  namespace MapsApp {     public partial class _Default : System.Web.UI.Page     {         [DLLImport("GeoUrbanApp.exe")]         public static extern double CalcFigure(double east, double north, double size); ... 

I am trying to call the CalcFigure function from the .exe. I've added it in the references, and trying to import it. All I get is:

The type or namespace name 'DLLImport' could not be found (are you missing a using directive or an assembly reference?)  The type or namespace name 'DLLImportAttribute' could not be found (are you missing a using directive or an assembly reference?) 

The solution most people find online is the "using System.Runtime.InteropServices;" but I have it.

like image 963
Vadiklk Avatar asked Sep 03 '12 08:09

Vadiklk


2 Answers

Try adding

using System.Runtime.InteropServices;

to your class, that's the namespace the DllImportAttribute resides in.

like image 106
Roz Avatar answered Sep 23 '22 02:09

Roz


It's DllImport not DLLImport

:)

like image 31
Kieren Johnstone Avatar answered Sep 24 '22 02:09

Kieren Johnstone