即使存在"使用InteropServices",也会丢失DLLImport

Vad*_*klk 22 c# dll

我有以下代码:

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);
...
Run Code Online (Sandbox Code Playgroud)

我试图从.exe调用CalcFigure函数.我在引用中添加了它,并尝试导入它.我得到的只是:

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?)
Run Code Online (Sandbox Code Playgroud)

大多数人在网上找到的解决方案是"使用System.Runtime.InteropServices;" 但我有它.

小智 59

尝试添加"using System.Runtime.InteropServices;" 在你的类中,这是DllImportAttribute所在的命名空间.

Razie


Kie*_*one 31

事实DllImport并非如此DLLImport

:)