无法识别引用的DLL中的方法? [英] Could not identify method in a referenced DLL?

查看:200
本文介绍了无法识别引用的DLL中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Portal.sln的现有解决方案,其中包含更多项目. HLS.Common是项目之一.我已将一些.NET参考DLL添加到Common项目(System.DirectoryServices和System.DirectoryServices.Protocols).我添加了一个公共类,并在该类中实现了一个公共方法.

我创建了另一个解决方案,并引用了HLS.Common DLL.尝试访问新创建的方法时,出现以下错误.

错误1找不到类型或名称空间名称"HLS"(您是否缺少using指令或程序集引用?)

如何解决该问题?

我的代码如下所示.

I''ve an existing solution called Portal.sln which contains more number of projects. HLS.Common is one of the projects. I''ve added some .NET reference DLLs to the Common project (System.DirectoryServices and System.DirectoryServices.Protocols). I''ve added a public class and implemented a public method in the class.

I create another solution and refereed the HLS.Common DLL. While trying to access the newly created method I get error as given below.

Error 1 The type or namespace name ''HLS'' could not be found (are you missing a using directive or an assembly reference?)

How to resolve the issue?

My code is shown below.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.DirectoryServices; 
    using System.DirectoryServices.Protocols; 
    using System.Net; 
namespace HLS.Common.LDAP
{
    public class LDAPCommunicator
    {
        public bool VerifyLDAPConnection()
        {
            try
            {
                //Some logic here to connect with LDAP return true; 
            }
            catch (Exception e)
            { return false; }
        }
    }
}


在客户端中,下面的主要方法中使用了代码.在using语句中添加了using HLS.Common.LDAP.


In the client, in main method below code is used. In using statements using HLS.Common.LDAP is added.

LDAPCommunicator ldapCommunicator = new LDAPCommunicator();
bool result = ldapCommunicator.VerifyLDAPConnection();

推荐答案

您正在直接添加对.DLL的引用,而不是对该.DLL的项目.

对.DLL项目进行更改并重新编译时,对该.DLL的引用不再有效,因为它依赖于程序集中的版本信息.

如果您添加项目引用而不是浏览到.DLL,此问题将消失.这样做的问题是,您必须将.DLL项目添加到包含引用的应用程序的解决方案中.
You''re adding a reference to the .DLL directly instead of the project for that .DLL.

When you make a change to the .DLL project and recompile, your reference to this .DLL is no longer valid as it relies on the version information in the assembly.

If you add a Project reference instead of browsing to the .DLL, this problem disappears. The problem with this is that you have to add the .DLL project to the solution containing your app holding the reference.


这篇关于无法识别引用的DLL中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆