0
votes

I made a application in asp.net c# using linq and oracle database.This application is working fine on Widows 7 32 bit local host.But When I deployed this application in windows server 2008 r2.It gives a following error.Guide me what is the following error.How Can I check this error on deployment server and How can I resolved this error

Specified cast is not valid. 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.InvalidCastException: Specified cast is not valid.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidCastException: Specified cast is not valid.]

System.Data.UnboxT`1.ValueField(Object value) +54

sis.<>c__DisplayClass55.b__0(DataRow r) +38

System.Linq.WhereEnumerableIterator`1.MoveNext() +156

System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +165

System.Linq.d__81`1.MoveNext() +472

System.Linq.Enumerable.Count(IEnumerable`1 source) +267

sis.regreport.Page_Load(Object sender, EventArgs e) +5015

System.Web.UI.Control.LoadRecursive() +71

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean

includeStagesAfterAsyncPoint) +3178

var vcolM = dt.AsEnumerable()
           .Where(r => r.Field<string>("MAJ") == (string)vprglist 
           && r.Field<string>("SPEC") == (string)vspecourse 
           && r.Field<string>("L_ABR_CODE") == (string)genderEng[1] 
           && r.Field<string>("reg") == (string)drRegion["reg"] 
           && r.Field<decimal>("year") == syrcnt)
           .Sum(r => Convert.ToInt32(r["strength"]));

All linq like above working fine in local pc.But giving error in windows server 2008.Where syrcnt is int.

1
put a breakpoint on the line, and examine exactly what type of object key is. When you know that, you will be in a better position to work out what kind of cast you need.Govinda Rajbhar
Because in deploymnet server How can I insert break pointWaqas Ali
Because in development server only DLLs files available.But in local pc application working fineWaqas Ali
can you describe when this error occurs? I mean When you try to redirect to some page or at the very first time you try your url in the address bar ?Krunal Patil
At the very first time.When I try url in the address barWaqas Ali

1 Answers

0
votes

The most likely cause of the InvalidCastException is the r.Field<string>("MAJ") , r.Field<decimal>("year") line. The Field<T> extension method will throw an InvalidCastException in the case where the actual type of the data doesn't match the type which was passed to Field<T>.

OR

lies in here Convert.ToInt32(r["strength"]), the strength might not be getting proper type

Honestly, I think you issues lies in the line r.Field<decimal>("year"). I may be wrong as there is not much information about the datatype of your variable syrcnt

Hence giving you the exception System.InvalidCastException: Specified cast is not valid