Tag: argumentexception

应用程序在调试时不会崩溃,但在正常运行时会发生

系统信息 Windows 10技术预览版(内部版本9926) Visual Studio社区2013 试图调试: [AT&T] Lumia 635(Windows 10技术预览版手机内置9941瓦特/ Lumia Cyan) [AT&T] Lumia 1520(带有Lumia Denim和PfD的Windows Phone 8.1) [Unlocked] BLU Win Jr(Windows Phone 8.1 with PfD) [Verizon] Lumia Icon(带有Lumia Denim和PfD的Windows Phone 8.1) 我试图在我的应用程序中使用位置服务。 以前,我有Visual Studio抛出错误。 这是一个ArgumentException ,消息“ Use of undefined keyword value 1 for event TaskScheduled in async ”。 谷歌搜索没有找到任何解决方案。 这是代码: Geolocator Locator = new […]

C#SerialPort#Open()方法因为端口名而抛出ArgumentException?

在我的本地机器上, Windows XP 端口(COM和LPT) COM3 RIM虚拟串行端口v2(COM4) RIM虚拟串行端口v2(COM5) 以下代码, using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO.Ports; using System.Threading; namespace OpenSerialPortTest { class Test { static void Main(string[] args) { foreach (String serialPortName in SerialPort.GetPortNames()) { SerialPort serialPort = new SerialPort(serialPortName); try { serialPort.Open(); // Line 19 Console.WriteLine(serialPort.PortName); } catch (Exception ex1) { Console.WriteLine(ex1); […]

自定义任务运行器方法抛出ArgumentException

由于CultureInfo没有从一个线程复制到另一个线程,我已经使用以下方法为我做这件事。 public static StartCustomTask(Action action, TaskCreationOptions tco = TaskCreationOptions.None) { var currentCult = Thread.CurrentThread.CurrentCuture; var currentUiCult = Thread.CurrentThread.CurrentUICulture; return Task.Factory.StartNew(() => { Thread.CurrentThread.CurrentCuture = currentCult; Thread.CurrentThread.CurrentUICulture = currentUiCult; action(); }, tco); } 基本上这个代码将文化信息从当前线程复制到将要执行action的线程。 我不知道为什么,但它抛出System.ArgumentException说Value does not fall within the expected range 。 我试图在主线程上定期运行动作,它完美无缺。 我的意思是,作为一个动作的方法本身没有问题,我想在上面的代码中有一个问题。 这是exception的堆栈跟踪 at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) at System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) at System.Web.HttpRequest.BuildUrl(Func`1 […]

Marshal.PtrToStructure抛出System.ArgumentException错误

我试图从键盘钩子的lParam获取KBDLLHOOKSTRUCT。 private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { KBDLLHOOKSTRUCT kbd = new KBDLLHOOKSTRUCT(); Marshal.PtrToStructure(lParam, kbd); // Throws System.ArguementException … 不幸的是,PtrToStructure正在投掷两个 A first chance exception of type ‘System.ArgumentException’ occurred in myprogram.exe 每次按下一个键都会出错。 它也会阻止该方法的发展。 MSNDA说: http : //msdn.microsoft.com/en-us/library/4ca6d5z7.aspx ArgumentException when: The structureType parameter layout is not sequential or explicit. -or- The structureType parameter is […]

空路径名称不合法

所以我正在尝试编译一个Asteroids游戏。 它几乎正常工作,所有文件都已到位等等…… 当它遇到这个代码时会出现问题。 FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); string myTempFile = @”F:\Documents\Junior School\Computer Programming (Java 1)\AsteroidsWithSound\AsteroidsWithSound\temp\mysound” + i.ToString() + “.wav”; 它给了我一个错误/警告,不知道究竟它叫什么,但它说 ArgumentException未处理。 空路径名称不合法。 我在网上看过这样的代码块导致了这个问题但却找不到解决方案。 任何帮助都是极好的。 编辑:文件名在此块中定义。 string filename = this.Player.FileName; this.Player.Open(“”); File.Delete(filename); this.isReady = true;