中了"The state information is invalid for this page and might be corrupted"的圈套!
2007-11-16 09:59
579 查看
前几天遇到一个页面错误,其实这个错误表面上看上去挺简单的,信息也很明确,可就这个错误让我整了一天。错误信息如下图:
[XmlSchemaException: The global element 'SM_DyColumns' has already been declared.]
System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e) +20
System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) +62
System.Xml.Schema.BaseProcessor.AddToTable(XmlSchemaObjectTable table, XmlQualifiedName qname, XmlSchemaObject item) +896
System.Xml.Schema.Preprocessor.Preprocess(XmlSchema schema, String targetNamespace, ArrayList imports) +4418
System.Xml.Schema.Preprocessor.Execute(XmlSchema schema, String targetNamespace, Boolean loadExternals) +698
System.Xml.Schema.XmlSchemaSet.PreprocessSchema(XmlSchema& schema, String targetNamespace) +214
System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, XmlSchema schema) +39
System.Xml.Schema.XmlSchemaSet.Add(XmlSchema schema) +158
System.Data.DataSet.ReadXSDSchema(XmlReader reader, Boolean denyResolving) +214
System.Data.DataSet.ReadXmlSchema(XmlReader reader, Boolean denyResolving) +371
System.Data.DataTable.DeserializeDataTable(SerializationInfo info, StreamingContext context, Boolean isSingleTable, SerializationFormat remotingFormat) +302
System.Data.DataTable..ctor(SerializationInfo info, StreamingContext context) +261
最后的办法就只能用排除法了,这几天改了一些东西,我想肯定有关系,于是我把改过的东西一个一个排除测试,最后令我惊讶的尽然是数据访问层的更改导致出现了这样的错误。这就纳闷了,数据层跟ViewState有什么关系啊?
然后我又把数据层一个一个方法的进行排除,终于定为到了一个方法上面,但是这个方法运行很正常。可把这个方法一换,页面就好了。
我在运行监视里看看是不是数据集返回的有问题,突然发现有两个相同的名字,然后想起前面那个与ViewState完全没关系的重复定义错误.该不会是问题出在这吧?可怎么会有两个相同的名字呢?存储过程肯定没问题,前版本调用的是同样的。
我看了看,原来出在这一句:
DataSet returnDataSet = new DataSet("TableName");
tempAdapter.Fill(returnDataSet, "TableName");
我new DataSet时给DataSet附上了一个名字,然后再Fill时又给DataSet的表里面附了一个相同的名字,这样数据集和表的名字就一样了。我把数据集的名字改掉后,页面的错误尽然消失了。
到这里,问题解决了,可留下个疑问,为什么会出现这样的错误呢?
再回头仔细看看那个重复定义的错误,感觉明白了点。ViewState把表格对象保存后,可能用的是xml格式,但是DataSet和DataTable的名字一样,导致xml结构上出了问题,所以当ViewState重新读取时发生错误。这也是我的理解,还希望大家给点意见。
为了方便大家把问题重现,我加了段测试代码:
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Default3 : System.Web.UI.Page
13
大家运行后就可以得到上面的错误,把DataSet的name改了后便正常了。
[XmlSchemaException: The global element 'SM_DyColumns' has already been declared.]
System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e) +20
System.Xml.Schema.BaseProcessor.SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) +62
System.Xml.Schema.BaseProcessor.AddToTable(XmlSchemaObjectTable table, XmlQualifiedName qname, XmlSchemaObject item) +896
System.Xml.Schema.Preprocessor.Preprocess(XmlSchema schema, String targetNamespace, ArrayList imports) +4418
System.Xml.Schema.Preprocessor.Execute(XmlSchema schema, String targetNamespace, Boolean loadExternals) +698
System.Xml.Schema.XmlSchemaSet.PreprocessSchema(XmlSchema& schema, String targetNamespace) +214
System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, XmlSchema schema) +39
System.Xml.Schema.XmlSchemaSet.Add(XmlSchema schema) +158
System.Data.DataSet.ReadXSDSchema(XmlReader reader, Boolean denyResolving) +214
System.Data.DataSet.ReadXmlSchema(XmlReader reader, Boolean denyResolving) +371
System.Data.DataTable.DeserializeDataTable(SerializationInfo info, StreamingContext context, Boolean isSingleTable, SerializationFormat remotingFormat) +302
System.Data.DataTable..ctor(SerializationInfo info, StreamingContext context) +261
最后的办法就只能用排除法了,这几天改了一些东西,我想肯定有关系,于是我把改过的东西一个一个排除测试,最后令我惊讶的尽然是数据访问层的更改导致出现了这样的错误。这就纳闷了,数据层跟ViewState有什么关系啊?
然后我又把数据层一个一个方法的进行排除,终于定为到了一个方法上面,但是这个方法运行很正常。可把这个方法一换,页面就好了。
我在运行监视里看看是不是数据集返回的有问题,突然发现有两个相同的名字,然后想起前面那个与ViewState完全没关系的重复定义错误.该不会是问题出在这吧?可怎么会有两个相同的名字呢?存储过程肯定没问题,前版本调用的是同样的。
我看了看,原来出在这一句:
DataSet returnDataSet = new DataSet("TableName");
tempAdapter.Fill(returnDataSet, "TableName");
我new DataSet时给DataSet附上了一个名字,然后再Fill时又给DataSet的表里面附了一个相同的名字,这样数据集和表的名字就一样了。我把数据集的名字改掉后,页面的错误尽然消失了。
到这里,问题解决了,可留下个疑问,为什么会出现这样的错误呢?
再回头仔细看看那个重复定义的错误,感觉明白了点。ViewState把表格对象保存后,可能用的是xml格式,但是DataSet和DataTable的名字一样,导致xml结构上出了问题,所以当ViewState重新读取时发生错误。这也是我的理解,还希望大家给点意见。
为了方便大家把问题重现,我加了段测试代码:
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
1using System;
2using System.Data;
3using System.Configuration;
4using System.Collections;
5using System.Web;
6using System.Web.Security;
7using System.Web.UI;
8using System.Web.UI.WebControls;
9using System.Web.UI.WebControls.WebParts;
10using System.Web.UI.HtmlControls;
11
12public partial class Default3 : System.Web.UI.Page
13
大家运行后就可以得到上面的错误,把DataSet的name改了后便正常了。
相关文章推荐
- asp.net中错误:"The state information is invalid for this page and might be corrupted."
- "The state information is invalid for this page and might be corrupted"错误的一个解决办法
- The state information is invalid for this page and might be corrupted解决办法
- Debug 之 The state information is invalid for this page and might be corrupted
- 错误处理:The viewstate is invalid for this page
- Xcode 安装不了文档,出现 Could not download and install iOS 8. The certificate for this server is invalid...
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- SharePoint解决The security validation for this page is invalid.
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- Sharepoint:The security validation for this page is invalid. Click Back in your Web browserSharepoin
- Sharepoint:The security validation for this page is invalid. Click Back in your Web browser
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- The requested page cannot be accessed because the related configuration data for the page is invalid
- The security validation for this page is invalid. Click Back in your Web错误
- [asp.net core]The requested page cannot be accessed because the related configuration data for the page is invalid.
- this bundle is invalid . new apps and app updates submitted to the app store must be built with publ
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built wit
- The requested page cannot be accessed because the related configuration data for the page is invalid
- 提交时提示错误This Bundle is invalid.New apps and app updates submitted to the App Store must be built with