最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

C# crifan 7557浏览

【问题】

C#程序中,有类似这样代码:

// Registers a hot key with Windows.
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

编译后出错:

D:\xxx\downloadSongtasteMusic\frmDownloadSonstasteMusic.cs(15,10): error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

【解决过程】

1.参照:C# 小结 二,添加了:

using System.Runtime.InteropServices;

然后就解决了。

转载请注明:在路上 » 【已解决】error CS0246: The type or namespace name ‘DllImport’ could not be found (are you missing a using directive or an assembly reference?)

91 queries in 0.251 seconds, using 19.35MB memory