Tag: exception

为什么在将字符串转换为float时会出现FormatException?

当我尝试将字符串转换为float时: Console.WriteLine(float.Parse(“6.59”)); 它引发了一个exception: 未处理的exception:System.FormatException:输入字符串不在正确的格式中。 at System.Number.ParseSingle(String value,NumberStyles options,NumberFormat Info numfmt) 当我这样尝试时: Console.WriteLine(Convert.ToSingle(“6.59”)); 它引发了同样的exception: 未处理的exception:System.FormatException:输入字符串不在正确的格式中。 at System.Number.ParseSingle(String value,NumberStyles options,NumberFormat Info numfmt) 在System.Convert.ToSingle(String value) 你能解释一下为什么会这样吗?

System.Net.ProtocolViolationException:在调用 GetResponse之前,必须将ContentLength字节写入请求流

我得到了 “System.Net.ProtocolViolationException:在调用Web请求的”BeginGetResponse“方法时,必须在调用[Begin] GetResponse”错误之前将ContentLength字节写入请求流。 这是我的代码: try { Stream dataStream = null; WebRequest Webrequest; Webrequest = WebRequest.Create(this.EndPointAddress); Webrequest.Credentials = new NetworkCredential(this.username, this.password); Webrequest.ContentType = “text/xml”; Webrequest.Method = WebRequestMethods.Http.Post; byteArray = System.Text.Encoding.UTF8.GetBytes(xmlRequest.Children[0].InnerXML); Webrequest.ContentLength = byteArray.Length; dataStream = Webrequest.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); RequestState rs = new RequestState(); rs.Request = Webrequest; IAsyncResult r = (IAsyncResult)Webrequest.BeginGetResponse(new AsyncCallback(RespCallback), rs); } catch (Exception […]

将窗体设置为父抛出exception“无法将顶级控件添加到控件”

我想从另一个表单访问表单的变量。 单击我的主窗体中的按钮,我想将我的主窗体设置为父窗口,然后调出另一个窗体(子窗体),其中我将访问主窗体的变量。 我的点击处理程序如下: private void btnSystem_Click(object sender, EventArgs e) { Form_EnterPassword EP = new Form_EnterPassword(); EP.Parent = this; //error: Top-level control cannot be added to a control EP.ShowDialog(); } 它编译好没有任何错误。 但是,当我运行Main窗体并单击System按钮时,它会抛出exception。 我使用相同的按钮单击在另一个代码(不是我的)中执行类似的操作,并且不会遇到任何错误(仅将主窗体设置为父窗口)。 我究竟做错了什么? 我的主代码中是否有导致此问题的内容?

WebKit.Net和OpenWebKitSharp错误:无法初始化激活上下文

我正在使用WebKit.Net和OpenWebKitSharp。 但是,一旦我尝试实例化WebKitBrowser,我就会收到一个错误:无法初始化激活上下文有人知道这是什么吗?

在C#中使用GDAL时出现exception

我开始在我的应用程序中使用gdal_csharp dll并读取geotiff文件。 但它说: The type initializer for ‘OSGeo.GDAL.GdalPINVOKE’ threw an exception. 这是我的代码 string fileName = @”/path to geotiff file”; OSGeo.GDAL.Dataset DS = OSGeo.GDAL.Gdal.Open(fileName, OSGeo.GDAL.Access.GA_ReadOnly); 有人可以帮忙吗? 编辑: 我有这些dll 这是完整的错误消息: 它说无法加载gdal_wrap 。 但是,当我要将dll添加到我的应用程序时,会显示以下消息:

当前上下文中不存在名称“$ exception”

今天我在我的工作中调试了一个应用程序。 我继续在我的一个catch块中设置断点,以便更详细地检查exception。 View Detail模式窗口正常打开,但不是向我显示exception的细节,而是抛出一个奇怪的错误,一个我从未得到的错误,也不知道它意味着什么: 错误说: 当前上下文中不存在名称“$ exception” 这令人沮丧,因为我在catch块范围内,所以我应该能够看到我的exception。 重新启动我的应用程序后,我设法调试它就好了。 这是唯一一次(到目前为止)我遇到了这个错误。 有谁知道这意味着什么以及如何解决它(无需重新启动应用程序)? 注意 :我使用的是Visual Studio 2012 Premium 。 版本11.0.61030.00更新4

你如何从Web服务中捕获抛出的SOAPexception?

我成功地在我的Web服务中抛出了一些soapexception。 我想捕获exception并访问被exception调用的字符串和ClientFaultCode。 以下是我在Web服务中的一个例外情况的示例: throw new SoapException(“You lose the game.”, SoapException.ClientFaultCode); 在我的客户端,我尝试从可能引发exception的Web服务运行该方法,并且我抓住了它。 问题是我的catch块没有做任何事情。 看这个例子: try { service.StartGame(); } catch { // missing code goes here } 如何访问使用抛出exception调用的字符串和ClientFaultCode?

更好的TypeInitializationException(innerException也为null)

介绍 当用户在NLog的配置中创建错误(如无效的XML)时,We(NLog)会抛出NLogConfigurationException 。 该例外包含描述错误的内容。 但是,如果第一次调用NLog来自静态字段/属性,有时这个NLogConfigurationException被System.TypeInitializationException “吃掉”。 例 例如,如果用户有此程序: using System; using System.Collections.Generic; using System.Linq; using NLog; namespace TypeInitializationExceptionTest { class Program { //this throws a NLogConfigurationException because of bad config. (like invalid XML) private static Logger logger = LogManager.GetCurrentClassLogger(); static void Main() { Console.WriteLine(“Press any key”); Console.ReadLine(); } } } 并且配置中存在错误,NLog抛出: throw new NLogConfigurationException(“Exception occurred […]

空字符串上的ToString

为什么第二个产生exception而第一个产生exception呢? string s = null; MessageBox.Show(s); MessageBox.Show(s.ToString()); 更新 – 我能理解的例外,令人费解的一点(对我而言)是第一部分没有显示exception的原因。 这与Messagebox没有任何关系,如下图所示。 例如: string s = null, msg; msg = “Message is ” + s; //no error msg = “Message is ” + s.ToString(); //error 第一部分似乎是隐式地将null转换为空字符串。

XDocument.Load(XmlReader)可能的exception

调用XDocument.Load(XmlReader)时可能抛出的exception有哪些? 当文档无法提供关键信息时,很难遵循最佳实践(即避免使用通用的try catch块)。 提前感谢你的帮助。