System.InvalidCastException: 无法将类型为“labelmanager2.dllApplicationClass”的 COM对象强制转换为

Web Service接口返回泛型的问题(System.InvalidCastException: 无法将类型为“System.Collections.Generic.List`1System.String”的对象强制转换为类型“System.String”)
& & &在使用C#写Web Service时遇到了个很奇怪的问题。返回值的类型是泛型(我用的是类似List&string&)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解。
&&&&& 后来在同事的帮助下,发现了规律,在返回值是泛型的接口前面,只要有返回值是字符串数组的接口,就会发生错误,如果把返回泛型的接口放到返回字符串数组的接口后面,就没问题了。
&&&&& 结合代码说明一下,代码如下:
[WebMethod]
public string[] HelloWorld1()
string[] str = new string[2];
str[0] = "Hello ";
str[1] = "World!";
[WebMethod]
public List&string& HelloWorld()
List&string& strList = new List&string&();
strList.Add("Hello ");
strList.Add("World!");
return strL
此时调用HelloWorld就会出现错误,错误如下
System.InvalidOperationException: 生成 XML 文档时出错。 & System.InvalidCastException: 无法将类型为&System.Collections.Generic.List`1[System.String]&的对象强制转换为类型&System.String[]&。
在 Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_ArrayOfString(Object o)
在 Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfStringSerializer1.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
内部异常堆栈跟踪的结尾
在 System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
在 System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
在 System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
在 System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
在 System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
在 System.Web.Services.Protocols.WebServiceHandler.Invoke()
  & &将HelloWorld和HelloWorld1都改为string数组或List&string&泛型就没有问题了。&本人觉得这个问题很奇怪,可能是VS2008的bug。写出来只是希望大家在使用时能够注意这个情况。
解释如下:
这是不是BUG,因为你是用了泛型,所以在序列化的时候要指定它的类型,加上:[XmlInclude(typeof(类型))] 就OK了。
感觉不是List不能序列化的问题,而是List在序列化以后,他的本质还是array,因此,如果在一个Webservice里存在两种序列化方式的的方法,就会存在问题。
Web Service在传输对象的时候,是把对象先序列化成为xml或者数据流,string对象是可以序列化,而List不是可序列化对象,所以在System.Xml.Serialization.XmlSerializer.Serialize 序列化的时候出错了
> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!
在使用C#写Web Service时遇到了个很奇怪的问题.返回值的类型是泛型(我用的是类似List&string&)的接口,测试时发现总是报什么无法转换为对象的错误,百思不得其解.
后来在同事的帮助下,发现了规律,在返回值是泛型的接口前面,只要有返回值是字符串数组的接口,就会发生错误,如果把返回泛型的接口放到返回字符串数组 ...
这次的系统包含两个子系统,所以做了一个分角色的身份验证系统. web.config &system.web&中设置 &authentication mode=&Forms&& &!--验证方式为窗体验证--& &forms name=&.ASPXAUTH& log ...
无法将类型为&System.Web.UI.WebControls.HiddenField&的对象强制转换为类型的错误的解决方法本文章将解决: 1.解释什么是System.Web.UI.LiteralControl 2.为什么会经常发生法将类型为&System.Web.UI.WebControls.HiddenField&quot ...
private void UpdateElement()
LoadXml();
XmlNodeList nodeList = xmlDoc.SelectSingleNode(&/configuration/appSettings&).ChildN//获取appSettings节点的所有 ...
在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1[SomeModel]”. 应该如此使用
System.Collections ...
保存图片控件上的图片到本地 出现错误:无法将类型为“System.Windows.Media.Imaging.BitmapFrameDecode”的对象强制转换为类型“System.Windows.Media.Imaging.BitmapImage”.try { System.Windows.Controls.MenuItem menuitem = send ...
无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”.此操作失败的原因是对 IID 为“{-C-046}”的接口的 COM 组件调用 QueryInterface
HRESULT:0x80032 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”.此操作失败的原因是对 IID 为“{-C-046}”的接口的 COM 组件调用 ...无法将类型为“System.Web.UI.WebControls.HyperLink”的对象强制转换为类型“System.Web.UI.WebControls.
[问题点数:40分,结帖人xiaomo1133]
无法将类型为“System.Web.UI.WebControls.HyperLink”的对象强制转换为类型“System.Web.UI.WebControls.
[问题点数:40分,结帖人xiaomo1133]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2012年 总版技术专家分年内排行榜第一2007年 总版技术专家分年内排行榜第二2006年 总版技术专家分年内排行榜第二2004年 总版技术专家分年内排行榜第二
2005年 总版技术专家分年内排行榜第三2003年 总版技术专家分年内排行榜第三2002年 总版技术专家分年内排行榜第三
本帖子已过去太久远了,不再提供回复功能。运行时报错:没法将类型为“System.Decimal”的对象强制转换为类型“System.String” - VB Dotnet当前位置:& &&&运行时报错:没法将类型为“System.Decimal”的对象运行时报错:没法将类型为“System.Decimal”的对象强制转换为类型“System.String”&&网友分享于:&&浏览:122次运行时报错:无法将类型为“System.Decimal”的对象强制转换为类型“System.String”未处理&
&&Message=无法将类型为“System.Decimal”的对象强制转换为类型“System.String”。
&&Source=System.Data
&&StackTrace:
&&&&&&&在&System.Data.SqlClient.SqlBuffer.get_String()
&&&&&&&在&System.Data.SqlClient.SqlDataReader.GetString(Int32&i)
&&&&&&&在&WindowsApplication1.Form3.Form3_Load(Object&sender,&EventArgs&e)&位置&C:\Documents&and&Settings\Administrator\My&Documents\VB.NET\dzd\dzd\Form3.vb:行号&29
&&&&&&&在&System.Windows.Forms.Form.OnLoad(EventArgs&e)
&&&&&&&在&System.Windows.Forms.Form.OnCreateControl()
&&&&&&&在&System.Windows.Forms.Control.CreateControl(Boolean&fIgnoreVisible)
&&&&&&&在&System.Windows.Forms.Control.CreateControl()
&&&&&&&在&System.Windows.Forms.Control.WmShowWindow(Message&&m)
&&&&&&&在&System.Windows.Forms.Control.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.ScrollableControl.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.ContainerControl.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.Form.WmShowWindow(Message&&m)
&&&&&&&在&System.Windows.Forms.Form.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&&m)
&&&&&&&在&System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr&hWnd,&Int32&msg,&IntPtr&wparam,&IntPtr&lparam)
&&&&&&&在&System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef&hWnd,&Int32&nCmdShow)
&&&&&&&在&System.Windows.Forms.Control.SetVisibleCore(Boolean&value)
&&&&&&&在&System.Windows.Forms.Form.SetVisibleCore(Boolean&value)
&&&&&&&在&System.Windows.Forms.Control.Show()
&&&&&&&在&WindowsApplication1.Form1.Button2_Click(Object&sender,&EventArgs&e)&位置&C:\Documents&and&Settings\Administrator\My&Documents\VB.NET\dzd\dzd\Form1.vb:行号&50
&&&&&&&在&System.Windows.Forms.Control.OnClick(EventArgs&e)
&&&&&&&在&System.Windows.Forms.Button.OnClick(EventArgs&e)
&&&&&&&在&System.Windows.Forms.Button.OnMouseUp(MouseEventArgs&mevent)
&&&&&&&在&System.Windows.Forms.Control.WmMouseUp(Message&&m,&MouseButtons&button,&Int32&clicks)
&&&&&&&在&System.Windows.Forms.Control.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.ButtonBase.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.Button.WndProc(Message&&m)
&&&&&&&在&System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&&m)
&&&&&&&在&System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&&m) 共&2&页:
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有无法将类型为“System.__ComObject”的 COM 对象强制转换为接口类型_百度知道报错:System.InvalidCastException: 无法将类型为&Microsoft.Office.Interop.Word.ApplicationClass&的 COM 对象强制转换为接口类型&Microsoft.Office.Interop.Word._Application&。此操作失败的原因是对 IID 为&{0-}&的接口的 COM 组件调用 QueryInterface 因以下错误而失败: 加载类型库/DLL 时出错。 (异常来自 HRESULT:0x80029C4A (TYPE_E_CANTLOADLIBRARY))。
在 System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
在 Microsoft.Office.Interop.Word.ApplicationClass.get_Selection()
在 BIMTClassLibrary.QuotationIndex.WriteContent()
原因:以前安装过wps后来卸载后,wps 会修改注册表相关office的未知相关项,导致vsto加载项报错;
解决方案:找到office安装包选择修复,即可解决;
阅读(...) 评论()}

我要回帖

更多关于 application label 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信