Visual Studio 2010發行Windows Form應用程式後,出現【System.ArgumentNullException 未處理】的解決方式

Visual Studio 2010發行Windows Form應用程式後,出現【System.ArgumentNullException 未處理】的解決方式

使用Visual Studio 2010發行Windows Form應用程式後,部分專案可以通過建置但無法執行並出現以下的錯誤訊息。

System.ArgumentNullException 未處理
  Message=值不能為 null。
參數名稱: activationContext
  Source=mscorlib
  ParamName=activationContext
  StackTrace:
       於 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       於 System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       於 System.Activator.CreateInstance(ActivationContext activationContext)
       於 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       於 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       於 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       於 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       於 System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

原來發行後VS2010會自動將專案的安全性設定為【啟用ClickOnce安全性設定】(如下圖)。

image

只要取消【啟用ClickOnce安全性設定】即可恢復正常。

參考資料:http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/a60f58c4-c285-4c14-899c-e4a21fc51afe/