C# Winform一开始就报错System.Reflection.TargetInvocationException

Helloworld3020 2020-11-06 10:02:51
各位大佬,

研究好几天了没找到原因,还请大佬们帮忙看看。

C# winform程序在使用过程中没有更改程序代码的情况下,重新开始运行后突然在program.cs程序中报错,之后就一直这样了,重启电脑也没有用,问题出现前的使用过程中存在用VS同时开启两个名称都叫Pannel的winform程序,但是没有改过代码。

static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Pannel());(报错处)
}
}

报错截图:


详细报错信息如下:
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Panel.Program.Main() in D:\sgmuserprofile\s9b5ga\Desktop\Test\Panel_Upate_20201021-ADD serial data MAX MIN AVG\Panel\Program.cs:line 19

This exception was originally thrown at this call stack:
System.Diagnostics.Process.Start()
System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
Panel.Pannel.Programming() in Pannel.cs
Panel.Pannel.btnStart_Click(object, System.EventArgs) in Pannel.cs
System.Runtime.CompilerServices.AsyncMethodBuilderCore.ThrowAsync.AnonymousMethod__6_0(object)

Inner Exception 1:
InvalidOperationException: Cannot start process because a file name has not been provided.
...全文
1939 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
八爻老骥 2020-11-06
  • 打赏
  • 举报
回复
Application.Run(new Pannel());这地方只能是个Form或Form的子类,你这个Pannel是什么?
earlsen 2020-11-06
  • 打赏
  • 举报
回复
最后提示“ 尚未提供文件名,因此无法启动进程” ,是不是启动文件路径不对,或者配置错误
八爻老骥 2020-11-06
  • 打赏
  • 举报
回复
引用 2 楼 Helloworld3020 的回复:
[quote=引用 1 楼 icoolno1 的回复:] Application.Run(new Pannel());这地方只能是个Form或Form的子类,你这个Pannel是什么?

这个Pannel就是Form,只是改了个名字而已。[/quote]

按钮事件里启动另一个进程,但找不到可执行文件。

This exception was originally thrown at this call stack:
System.Diagnostics.Process.Start()
System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
Panel.Pannel.Programming() in Pannel.cs
Panel.Pannel.btnStart_Click(object, System.EventArgs) in Pannel.cs
System.Runtime.CompilerServices.AsyncMethodBuilderCore.ThrowAsync.AnonymousMethod__6_0(object)
qq_30335331 2020-11-06
  • 打赏
  • 举报
回复
This exception was originally thrown at this call stack: System.Diagnostics.Process.Start() System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo) Panel.Pannel.Programming() in Pannel.cs Panel.Pannel.btnStart_Click(object, System.EventArgs) in Pannel.cs System.Runtime.CompilerServices.AsyncMethodBuilderCore.ThrowAsync.AnonymousMethod__6_0(object) 你是不是点击了按钮 才报的错???
qq_30335331 2020-11-06
  • 打赏
  • 举报
回复
把异常设置的选项都勾选上 别有事没事 try catch 错误的地方根本不在这 在form里面
Helloworld3020 2020-11-06
  • 打赏
  • 举报
回复
再补充一下,同样的代码,放到其他的电脑有时候是可以运行的,但在我的电脑上跑就一直有问题。
Helloworld3020 2020-11-06
  • 打赏
  • 举报
回复
引用 1 楼 icoolno1 的回复:
Application.Run(new Pannel());这地方只能是个Form或Form的子类,你这个Pannel是什么?
这个Pannel就是Form,只是改了个名字而已。

111,113

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧