2013-05-18 30 views
6

我使用Visual Studio 2010设计一个网页,我已经使用了层如何在类型名称中指定程序集显式?

编程,我使用的是gidview和ObjectDataSource,但我得到这个exeption:

"The type 'WebApplication4.view1' is ambiguous: it could come from assembly 
'C:\Users\EHSAN\AppData\Local\Temp\Temporary ASP.NET 
    Files\root\d04444bc\d654bde6\App_Code.i0fp6yrj.DLL' or from assembly 
    'C:\Users\EHSAN\Documents\Visual Studio 
    2010\Projects\WebApplication4\WebApplication4\bin\WebApplication4.DLL'. Please 
    specify the assembly explicitly in the type name." 

我把我的代码在这里:

这是我web.aspx:

<asp:ObjectDataSource ID="ObjectDataSource1" Runat="server" TypeName="WebApplication4.view1" 
     SelectMethod="Search" OldValuesParameterFormatString="original_{0}" > 

     </asp:ObjectDataSource> 

,这是在App_Code文件夹BAL的search.cs文件:

namespace WebApplication4 
{ 
    using System; 
    using System.Collections.Generic; 
    using System.Text; 
    using System.Linq; 
    using System.Data; 
public class view1 : System.Web.UI.Page 
    { 
     public view1() 
     { } 

     public List<person> Search() 
     { 
      List<person> persons = new List<person>(); 
      DataSet ds = PersonsDB.Search(); 

      foreach (DataRow row in ds.Tables[0].Rows) 
      { 

       persons.Add(new person((String)row["id"], (String)row["nam"], (String)row["family"], (String)row["namepedar"], (String)row["shshenas"], (String)row["codemelli"])); 
      } 


      return persons; 
     } 
    } 

问题在哪里?

回答

2

当项目中存在两个具有相同名称的类时(通常是由于复制和粘贴错误)时,会发生这种情况。 你可以检查其他地方是否有其他类别view1

如果这不是问题,尝试清理您的临时网页文件,如下所示: Clearing out temporary asp.net files

+0

感谢您的回复,但是,我的解决方案中没有任何其他类名为view1! –

+0

您是否尝试清除临时网络文件? – Augusto

10

尝试移动Search.cs鱼贯而出App_Code文件夹,看看它是否工作。我遇到了同样的问题,然后将它移出并开始工作。

+0

也为我工作。我想知道为什么。 – RazvanR

+0

解决了我的问题 –

3

我有同样的错误。我创建了WebUserControl项目,其中的控件名为control1。我也有项目网站1其中我用我的控制1(使用项目构建事件复制控制1网站1)。它工作正常,但后来我复制了我的Website1项目并更名为Website2项目。在网站2我得到了这个错误。清洁,重建没有解决。我删除了Website2 \ bin文件夹中的所有文件并构建了Website2项目。错误已解决。

+0

这应该是答案。了解这个问题很重要。但简而言之,解决方案也是如此。 – KannedFarU

0

当您添加对解决方案的引用时,请将该文件属性复制到本地以“False”。所以当我们构建解决方案时它不会被复制,我们也不会得到错误。这个对我有用。请试试这个。

0

右键单击网站/ web应用程序属性,并使用预期的名称设置“组件名称”字段。例如:如果应用程序被命名为XYZ并使用命名空间命名为companyname.dept.XYZ,那么应用程序可能有2个单独的dll。 XYZ.dllcompanyname.dept.XYZ.dll这可能会导致冲突。

相关问题