各位前辈:
   我用VS.net2005添加新项目,并建立一个类文件(CS文件),将cs代码拷入(Microsoft快速入门教程源码),然后点击生成,将类库生成到bin文件中(在网站的根目录)
在网站项目上点右键,添加引用->浏览->找到DLL文件,然后就是以下的代码,但系统提示错误,请各位前辈帮帮小弟,谢谢!
运行时的错误信息:
未能加载文件或程序集“HelloObj”或它的某一个依赖项。系统找不到指定的文件。代码如下:
CS文件代码:
using System.Reflection;[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("快速入门教程汇编")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft?QuickStart Tutorials")]
[assembly: AssemblyCopyright("?Microsoft Corporation.  All rights reserved.")]
[assembly: AssemblyTrade("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]namespace HelloWorld
{
    using System;
    using System.Text;    public class HelloObj
    {
        private String _name;        public HelloObj()
        {
            _name = null;
        }        public String FirstName
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }        public String SayHello()
        {
            StringBuilder sb = new StringBuilder("Hello ");
            if (_name != null)
                sb.Append(_name);
            else
                sb.Append("World");
            sb.Append("!");
            return sb.ToString();
        }
    }
}aspx.cs文件代码:using System;
using System.Data;
using HelloWorld;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class SubCom_HelloObj : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HelloObj comp = new HelloObj();
        message.InnerHtml += comp.SayHello() + "<p>";        comp.FirstName = "Microsoft.Net框架";
        message.InnerHtml += comp.SayHello() + "<p>";        comp.FirstName = "ASP.NET";
        message.InnerHtml += comp.SayHello() + "<p>";        comp.FirstName = "World!!!";
        message.InnerHtml += comp.SayHello();
    }
}Web.Config文件代码
<?xml version="1.0" encoding="utf-8"?>
<!-- 注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来 
     配置应用程序的设置。可以使用 Visual Studio 中的“网站”->“ASP.NET 配置”
     选项。
     设置和注释的完整列表在
     machine.config.comments 中,该文件通常位于 \Windows\Microsoft.NET\Framework\v2.0.xxxxx\Config 中
 -->
<!--<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>    </system.web>
</configuration>--><configuration>
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="HelloObj"/>
      </assemblies>
    </compilation>
  </system.web>
</configuration>aspx文件代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloObj.aspx.cs" Inherits="SubCom_HelloObj" %>
<%@ Import Namespace="HelloWorld" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body style="font:10.5pt 宋体">
    <form id="form1" runat="server">
    <div>
      <h3>一个简单的托管组合</h3>
      <h5>对象输入</h5>
      <span id="message" runat="server" />
    </div>
    </form>
</body>
</html>

解决方案 »

  1.   

    //using   System.Reflection; //[assembly:   AssemblyTitle("")] 
    //[assembly:   AssemblyDescription("快速入门教程汇编")] 
    //[assembly:   AssemblyConfiguration("")] 
    //[assembly:   AssemblyCompany("Microsoft   Corporation")] 
    //[assembly:   AssemblyProduct("Microsoft?QuickStart   Tutorials")] 
    //[assembly:   AssemblyCopyright("?Microsoft   Corporation.     All   rights   reserved.")] 
    //[assembly:   AssemblyTrade("")] 
    //[assembly:   AssemblyCulture("")] 
    //[assembly:   AssemblyVersion("1.0.*")] namespace   HelloWorld 

            using   System; 
            using   System.Text;         public   class   HelloObj 
            { 
                    private   String   _name;                 public   HelloObj() 
                    { 
                            _name   =   null; 
                    }                 public   String   FirstName 
                    { 
                            get 
                            { 
                                    return   _name; 
                            } 
                            set 
                            { 
                                    _name   =   value; 
                            } 
                    }                 public   String   SayHello() 
                    { 
                            StringBuilder   sb   =   new   StringBuilder("Hello   "); 
                            if   (_name   !=   null) 
                                    sb.Append(_name); 
                            else 
                                    sb.Append("World"); 
                            sb.Append("!"); 
                            return   sb.ToString(); 
                    } 
            } 
    } 个人建议:先买本比较薄的asp.net的书来学习。