找不到在ObjectDataSource的TypeName属性中指定的类型 [英] The type specified in the TypeName property of ObjectDataSource could not be found

查看:75
本文介绍了找不到在ObjectDataSource的TypeName属性中指定的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于要求,所有网站.cs文件都存储在App_Code目录中,并编译到App_Code.dll中.尝试访问网站的特定页面时出现错误.

Because of requirements, all website .cs files are stored inside App_Code directory and compiled into App_Code.dll. There is an error when I try to access one specific page of the website.

Description: An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more
information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The type
specified in the TypeName property of ObjectDataSource
'DataSourceSubmissionList' could not be found.

我有一个由ObjectDataSource填充的Gridview控件.代码如下:

I have a Gridview control which is populated by ObjectDataSource. Code is below:

/layouts/Portal/Company/Application/code.ascx:

<%@ Control Language="c#" AutoEventWireup="true"
CodeFile="~/layouts/Portal/Company/Application/code.ascx.cs"
Inherits="Project.WebUserControls.myapplications.sublayout" %>

<dx:ASPxGridView ID="ASPxGridView1"
  runat="server"
  DataSourceID="DataSourceSubmissionList"
  KeyFieldName="SubmissionId"
</dx:ASPxGridView>

<asp:ObjectDataSource
  ID="DataSourceSubmissionList"
  runat="server"
  TypeName="Project.WebUserControls.myapplications.sublayout">
</asp:ObjectDataSource>

/layouts/Portal/Company/Application/code.ascx.cs:

namespace Project.WebUserControls.myapplications
{  
    public partial class sublayout: System.Web.UI.UserControl 
    {
    }
}

当我在code.ascx文件中使用此行以获取完全限定的类型名称时...

When I use this line in the code.ascx file to get the fully qualified typename...

<% Response.Write(typeof(Project.WebUserControls.myapplications.sublayout).AssemblyQualifiedName); %>

将其打印在页面上.

Project.WebUserControls.myapplications.sublayout, App_Web_oiftguk4,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

但是,在ObjectDataSource TypeName中使用此确切类型(Project.WebUserControls.myapplications.sublayout)会导致错误.

However, using this exact type (Project.WebUserControls.myapplications.sublayout) in the ObjectDataSource TypeName results in error.

关于此错误消息,我经历了很多问题.我已经读过,可能的解决方案可能是在TypeName属性中同时使用名称空间和程序集名称,像这样.但是我不能这样做,因为代码是动态编译的,并且程序集名称不断变化.

I have gone through many questions about this error message. I have read that possible solution could be using both the namespace and assembly name in the TypeName property, like this. But I can't do that because code is compiled dynamically and assembly name keeps changing.

另一件事-仅当使用CodeFile方法时,才会发生此错误.如果我切换到CodBehind,没问题.

Another thing - this error occurs only when CodeFile approach is used. If I switch to CodBehind, no problem.

这种行为可能是什么原因?

What could be the reason for this behavior?

推荐答案

我通过在Page_Init期间初始化TypeName属性,而不是直接在ObjectDataSource中指定TypeName来解决了这个问题:

I solved the issue by initializing TypeName property during Page_Init and not specifying TypeName directly in the ObjectDataSource:

/layouts/Portal/Company/Application/code.ascx.cs:

public void Page_Init(object o, EventArgs e)
{
   DataSourceSubmissionList.TypeName = this.GetType().AssemblyQualifiedName;
}

/layouts/Portal/Company/Application/code.ascx:

<asp:ObjectDataSource
  ID="DataSourceSubmissionList"
  runat="server"
</asp:ObjectDataSource>

这篇关于找不到在ObjectDataSource的TypeName属性中指定的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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