View Single Post
  #1 (permalink)  
Old January 15th, 2008, 02:24 PM
Jophie Jophie is offline
Authorized User
 
Join Date: Oct 2007
Location: Arlington, VA, USA.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default System.InvalidCastException; System.Reflection.Tar

1. I have the exactly problem: "System.InvalidCastException:Specified cast is not valid" after I had added more input fields in AddEditArticle page.
I did add fields before and had some problems with store procedures. After I had fixed the store procedures and then it have been worked fine.
This time, I can't fix it as I did last time. Then I found this http://p2p.wrox.com/topic.asp?TOPIC_ID=54996 here and I tried to put Convert.ToInt32(reader["ArticleID"]) in ArticlesProvider.cs; however, it won't work for my case.

The errors pop up when I click on "BrowseArticle" which has a control: ArticleListing.ascx.

Also, I had more error message:

Line 106: protected virtual ArticleDetails GetArticleFromReader(IDataReader reader, bool readBody)
Line 107: {
Line 108: ArticleDetails article = new ArticleDetails(
Line 109: Convert.ToInt32(reader["ArticleID"]),
Line 110: (DateTime)reader["AddedDate"],

[InvalidCastException: Specified cast is not valid.]
   WS.YourAdviceSite.DAL.ArticlesProvider.GetArticleF romReader(IDataReader reader, Boolean readBody) in e:\01_13\YA_Web\App_Code\DAL\ArticlesProvider.cs:1 08
   WS.YourAdviceSite.DAL.ArticlesProvider.GetArticleC ollectionFromReader(IDataReader reader, Boolean readBody) in e:\01_13\YA_Web\App_Code\DAL\ArticlesProvider.cs:1 57
   WS.YourAdviceSite.DAL.SqlClient.SqlArticlesProvide r.GetPublishedArticles(DateTime currentDate, Int32 pageIndex, Int32 pageSize) in e:\01_13\YA_Web\App_Code\DAL\SqlClient\SqlArticles Provider.cs:184
   WS.YourAdviceSite.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 startRowIndex, Int32 maximumRows) in e:\01_13\YA_Web\App_Code\BLL\Articles\Article.cs:4 66
   WS.YourAdviceSite.BLL.Articles.Article.GetArticles (Boolean publishedOnly, Int32 categoryID, Int32 startRowIndex, Int32 maximumRows) in e:\01_13\YA_Web\App_Code\BLL\Articles\Article.cs:4 87

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(Objec t target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +17
   System.Web.UI.WebControls.ObjectDataSourceView.Inv okeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +676
   System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +2659
   System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +84
   System.Web.UI.WebControls.DataBoundControl.Perform Select() +153
   System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +99
   System.Web.UI.WebControls.GridView.DataBind() +23
   WS.YourAdviceSite.UI.Controls.ArticleListing.Page_ Load(Object sender, EventArgs e) in e:\01_13\YA_Web\Controls\ArticleListing.ascx.cs:14 4
   System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +31
   System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +68
   System.Web.UI.Control.OnLoad(EventArgs e) +88
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Control.LoadRecursive() +158
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint

---------
2. Moremore, I tried Tara's solution:
http://p2p.wrox.com/topic.asp?TOPIC_...tem.Reflection

Using "if (reader.Read()) {...}". But it can't solve my problem neither.

-----------
PLEASE HELP IF YOU KNOW WHAT IS WRONG. THANK YOU VERY MUCH.



jophie
__________________
jophie