我创建了一个游戏,其中包含另一个类中列出的许多方法... 所以我想全局使用这个类,所以我将它存储在一个 DLL 中(以便能够在其他几个项目中使用它)
但不知何故,Visual Studio 找不到我引用的那个 DLL 的命名空间!
我做错了什么吗? “fncs”DLL 的命名空间也称为“fncs”... 它们都是在相同版本的 .NET 中创建的... 提前致谢!
动态链接库:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
namespace fncs {
class io {
public static bool write(string dir, object[] obj) {
try {
File.WriteAllLines(dir, ((System.Collections.IEnumerable)obj).Cast<object>().Select(x => x.ToString()).ToArray());
} catch (Exception e) {
return false;
} return true;
}
public static string read(string dir) {
StreamReader r = new StreamReader(dir);
return r.ReadToEnd();
}
public static void saveToServer(string x, string y) {
// hidden
}
}
class rc {
public static void echo(object obj) {
Console.WriteLine(obj.ToString());
}
public static string get() {
return Console.ReadLine();
}
}
class math {
public static int add(int a, int b) {
return a + b;
}
}
class web {
public static string getWebContent(string url) {
WebClient c = new WebClient();
string s;
try {
s = c.DownloadString(url);
} catch (WebException w) {
return w.ToString();
} return s;
}
public static string OpenSQL() {
SQLConnection SQL = new SQLConnection();
return SQL.BindStatus();
}
public static string post(string Url, params string[] postdata) {
string result = string.Empty;
string data = string.Empty;
System.Text.ASCIIEncoding ascii = new ASCIIEncoding();
if (postdata.Length % 2 != 0) {
Console.WriteLine("Parameters must be even , \"user\" , \"value\" , ... etc");
return string.Empty;
}
for (int i = 0; i < postdata.Length; i += 2) {
data += string.Format("&{0}={1}", postdata[i], postdata[i + 1]);
}
data = data.Remove(0, 1);
byte[] bytesarr = ascii.GetBytes(data);
try {
WebRequest request = WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytesarr.Length;
System.IO.Stream streamwriter = request.GetRequestStream();
streamwriter.Write(bytesarr, 0, bytesarr.Length);
streamwriter.Close();
WebResponse response = request.GetResponse();
streamwriter = response.GetResponseStream();
System.IO.StreamReader streamread = new System.IO.StreamReader(streamwriter);
result = streamread.ReadToEnd();
streamread.Close();
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
return result;
}
}
class SQLConnection {
public string conn_bind;
public SQLConnection() {
//hidden
}
public string BindStatus() {
return conn_bind;
}
}
}
最佳答案
- 在解决方案资源管理器中,右键单击您为 fncs 添加的引用。
- 选择“在对象浏览器中查看”。这将调出项目看到的所有程序集。
- 在树中选择 fncs 并在右下角的窗口中验证,是的,这就是您认为应该包括的程序集。 (很可能是)。
- 打开 fncs 并查看 namespace 。
- 应该有一个 FNCS 命名空间,如果没有就回到 fncs 项目并确定原因。
- 如果有 FNCS 命名空间,验证其中有一个类 目标 fncs,然后在正确的窗口中再次检查它以验证它是否是您想要的。
----更新----
您的类(class)需要公开。默认为内部,这意味着只能在程序集中查看。将其公开并重建后,您的其他项目应该可以看到它。
关于c# - Visual Studio 没有读取我的 dll? (作为命名空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410179/