简体   繁体   English

我在Web应用程序中添加了dll,但是该dll无法访问类名,这是什么问题?

[英]I am adding dll in web application but that dll cannot access the class names what is the problem?

I am using a dll(NEWDAO.dll) in web application. 我在Web应用程序中使用dll(NEWDAO.dll)。 It has a cs file, I can access that class name in web application but it is not came what is the problem, pls give me any suggestion 它有一个cs文件,我可以在Web应用程序中访问该类的名称,但是问题没有解决,请给我任何建议

in NEWDAO name space class is DBConnection code is 在NEWDAO名称空间类中是DBConnection代码是

  using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace NEWDAO
{
    class DbConnection
    {
        private int _EmpName;
        private string _Name;
        private decimal _Salary;
        private DateTime _CreatedDate;
        public bool Flag = false;
        DataSet ds = new DataSet();
        SqlConnection m_Con = new SqlConnection("Server=*******,dataSource=Test,user name=sa,password=*******");
        SqlCommand m_Cmd = new SqlCommand();

        public int EmpNo
        {
            get
            {
                return _EmpName;
            }
            set
            {
                _EmpName = value;
            }
        }

        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        public decimal Salary
        {
            get
            {
                return _Salary;
            }
            set
            {
                _Salary = value;
            }
        }

        public DateTime CreatedDate
        {
            get
            {
                return _CreatedDate;
            }
            set
            {
                _CreatedDate = value;
            }
        }
        /// <summary>
        /// Insert the Emp values
        /// </summary>
        public bool EmpInsert()
        {
            Flag = false;
            m_Con.Open();
            SqlCommand m_Cmd = new SqlCommand("usp_EmpInsert", m_Con);
            m_Cmd.CommandType = CommandType.StoredProcedure;
            m_Cmd.Parameters.AddWithValue("@EmpName", EmpNo);
            m_Cmd.Parameters.AddWithValue("@Name", Name);
            m_Cmd.Parameters.AddWithValue("@Salary", Salary);
            m_Cmd.Parameters.AddWithValue("@CreatedDate", CreatedDate);
            if (m_Cmd.ExecuteNonQuery() >= 0)
            {
                Flag = true;
                return Flag;

            }
            else
            {
                return Flag;
            }
            m_Con.Close();
        }

        /// <summary>
        /// Display the values
        /// </summary>
        public bool EmpSelect(out DataSet oDS)
        {
            Flag = false;
            m_Con.Open();
            SqlCommand m_Cmd = new SqlCommand("usp_EmpInsert", m_Con);
            m_Cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter ad = new SqlDataAdapter("usp_EmpInsert", m_Con);
            ad.Fill(ds, "EMP");
            if (ds != null)
            {
                oDS = ds;
                Flag = true;
                return Flag;
            }
            else
            {
                oDS = null;
                return Flag;
            }
            m_Con.Close();

        }
    }
}

thank you hemanth 谢谢你的实力

You should also check to see if your class is public. 您还应该检查一下您的班级是否公开。 The default access modifier is internal. 默认访问修饰符是内部的。

Class should be public to access from another assembly. 类应该是公共的 ,以便从另一个程序集访问。 Internal is the default if no access modifier is specified. 如果未指定访问修饰符,则“ 内部”为默认设置。

  • Set the class as public ( public class DbConnection ) 将类设置为public( public class DbConnection

  • Add reference to your dll 添加对您的dll的引用

you can access this class as bellow 您可以按以下方式访问该课程

NEWDAO.DbConnection

Or you can add a using directives ( using NEWDAO; ) and access DbConnection directly 或者您可以添加一个using指令using NEWDAO; )并直接访问DbConnection

You need to add a using directive that has the namespace where this class exists in, or use the full name, including the namespace. 您需要添加一个using指令,该指令具有此类所在的名称空间,或使用全名,包括名称空间。

So, if the full class name is: 因此,如果完整的类名是:

DAO.SourceWordDoc

Either add a: 要么添加一个:

using DAO;

Or use the full name - DAO.SourceWordDoc . 或使用全名DAO.SourceWordDoc

Maybe your application is targeting a different target framework than the assemblie. 也许您的应用程序针对的目标框架不同于汇编程序。 Eg for a WPF Project, check 例如,对于WPF项目,请检查

Properties -> Application -> Target Framework 属性->应用程序->目标框架

Possible your DLL requires the full framework and your app is only targeting the client profile. 可能您的DLL需要完整的框架,而您的应用仅针对客户端配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM