为什么会出现错误CS0246:找不到类型或名称空间名称? [英] Why am I getting error CS0246: The type or namespace name could not be found?
问题描述
我正在使用 Snarl C#API 发送通知给咆哮.
I am using Snarl C# API to send notifications to snarl.
现在,我已将上述url的内容保存在名为SnarlNetwork.cs
的文件中,而我的test.cs
文件的内容是:
Now I have saved the content of above url in a file named SnarlNetwork.cs
and the content of my test.cs
file are:
using SnarlNetworkProtocol;
using System;
class test
{
public static void Main(String[] args)
{
SNP snarl_object = new SNP();
string hostname = "localhost";
string hostport = "9887";
string appName = "Spotify";
bool val = snarl_object.register(hostname, hostport, appName);
if (val == true)
{
string title = "hello";
string message = "world";
string timeout = "5";
bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);
if (newval == true)
{
Console.WriteLine("sucessfull");
}
}
}
}
现在,当我尝试使用csc test.cs
编译test.cs文件时,出现以下错误:
Now when I try to compile my test.cs file using csc test.cs
I get the following error:
C:\Users\Noob\csharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)
那么,我在这里做错了什么,因为根据我的看法,我没有错过任何using directive
.
So, what am I doing wrong here because according to me I am not missing any using directive
.
推荐答案
这是问题所在
C:\Users\Noob\csharp>csc test.cs
您尚未添加对DLL的引用.您需要类似的东西:
You haven't added a reference to the DLL. You need something like:
C:\Users\Noob\csharp>csc test.cs /r:SnarlNetwork.dll
(或任何称为程序集的东西).
(or whatever the assembly is called).
或者,如果您还没有将其作为单独的库,则只需编译两个文件:
Alternatively, if you haven't got it as a separate library, just compile both files:
C:\Users\Noob\csharp>csc test.cs SnarlNetwork.cs
如果您尚未编译程序集,但想要 ,则可以使用:
If you haven't compiled an assembly but want to, you can use:
csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs
csc Test.cs /r:SnarlNetwork.dll
(实际上,在这种特殊情况下,不需要指定输出文件,但是更清楚了...)
(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)
这篇关于为什么会出现错误CS0246:找不到类型或名称空间名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!