简体   繁体   English

指定的演员表无效。 Windows Server 2008 R2中显示错误

[英]Specified cast is not valid. error shows in window server 2008 r2

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 我使用linq和oracle数据库在asp.net c#中创建了一个应用程序,该应用程序在Widows 7 32位本地主机上运行良好,但是当我在Windows Server 2008 R2中部署此应用程序时,出现以下错误。以下错误。如何在部署服务器上检查此错误以及如何解决此错误

Specified cast is not valid. 指定的演员表无效。 Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 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. 异常详细信息:System.InvalidCastException:指定的强制转换无效。

Source Error: 源错误:

An unhandled exception was generated during the execution of the current web request. 当前Web请求的执行期间生成了未处理的异常。 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.] [InvalidCastException:指定的强制转换无效。]

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

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

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

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

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

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

sis.regreport.Page_Load(Object sender, EventArgs e) +5015 sis.regreport.Page_Load(对象发送者,EventArgs e)+5015

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

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

includeStagesAfterAsyncPoint) +3178 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. 上面的所有linq在本地pc上都能正常工作,但是在Windows Server 2008中给出错误。

The most likely cause of the InvalidCastException is the r.Field<string>("MAJ") , r.Field<decimal>("year") line. InvalidCastException的最可能原因是r.Field<string>("MAJ") , r.Field<decimal>("year")行。 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> . 如果数据的实际类型与传递给Field<T>的类型不匹配,则Field<T>扩展方法将引发InvalidCastException

OR 要么

lies in here Convert.ToInt32(r["strength"]) , the strength might not be getting proper type 位于此处Convert.ToInt32(r["strength"]) ,强度可能未获得正确的类型

Honestly, I think you issues lies in the line r.Field<decimal>("year") . 老实说,我认为您的问题在r.Field<decimal>("year") I may be wrong as there is not much information about the datatype of your variable syrcnt 我可能错了,因为关于变量syrcnt的数据类型的信息syrcnt

Hence giving you the exception System.InvalidCastException: Specified cast is not valid 因此,给您异常System.InvalidCastException: Specified cast is not valid

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM