各位大佬,
研究好幾天了沒找到原因,還請大佬們幫忙看看。
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.
uj5u.com熱心網友回復:
Application.Run(new Pannel());這地方只能是個Form或Form的子類,你這個Pannel是什么?uj5u.com熱心網友回復:
這個Pannel就是Form,只是改了個名字而已。
uj5u.com熱心網友回復:
再補充一下,同樣的代碼,放到其他的電腦有時候是可以運行的,但在我的電腦上跑就一直有問題。uj5u.com熱心網友回復:
把例外設定的選項都勾選上 別有事沒事 try catch 錯誤的地方根本不在這 在form里面uj5u.com熱心網友回復:
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)
你是不是點擊了按鈕 才報的錯???
uj5u.com熱心網友回復:
按鈕事件里啟動另一個行程,但找不到可執行檔案。
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)
uj5u.com熱心網友回復:
最后提示“ 尚未提供檔案名,因此無法啟動行程” ,是不是啟動檔案路徑不對,或者配置錯誤轉載請註明出處,本文鏈接:https://www.uj5u.com/net/205227.html
標籤:C#
