c# - Visual Studio 没有读取我的 dll? (作为命名空间)

标签 c# visual-studio

我创建了一个游戏,其中包含另一个类中列出的许多方法... 所以我想全局使用这个类,所以我将它存储在一个 DLL 中(以便能够在其他几个项目中使用它)

但不知何故,Visual Studio 找不到我引用的那个 DLL 的命名空间!

Here's an image

我做错了什么吗? “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;
        }
    }
}

最佳答案

  1. 在解决方案资源管理器中,右键单击您为 fncs 添加的引用。
  2. 选择“在对象浏览器中查看”。这将调出项目看到的所有程序集。
  3. 在树中选择 fncs 并在右下角的窗口中验证,是的,这就是您认为应该包括的程序集。 (很可能是)。
  4. 打开 fncs 并查看 namespace 。
  5. 应该有一个 FNCS 命名空间,如果没有就回到 fncs 项目并确定原因。
  6. 如果有 FNCS 命名空间,验证其中有一个类 目标 fncs,然后在正确的窗口中再次检查它以验证它是否是您想要的。

----更新----

您的类(class)需要公开。默认为内部,这意味着只能在程序集中查看。将其公开并重建后,您的其他项目应该可以看到它。

关于c# - Visual Studio 没有读取我的 dll? (作为命名空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410179/

相关文章:

.net - 如何在 Visual Studio 2010 中添加 PNG 资源?

c# - Visual Studio Server Explorer 是否支持自定义数据库提供程序?

c# - 基于OS平台的DllImport

c# - 测试一个值是否包含在 Dictionary<TKey, List<TValue>> 中

c# - 如何设置RichTextBox光标到末尾?

c# - MySQL 与 Visual Studio : Authentication Method 'mysql_clear_password' Not Supported, 如何修复?

c++ - 如何隐藏类的私有(private)成员?

c# - IComparable<T> 不实现

c# - 如何在请求结束时释放资源并在 ASP.NET 5/Core 中处理注入(inject)的服务?

c++ - 关于如何使用简单的 C++ 库(不使用 .net)和使用该库的 C++ 项目创建 .sln 的基本说明?