debug模式下程序可以通过,releaes下就报错了。问题是路径不对了。

解决方案 »

  1.   

    你看看报错的代码附近,是不是有#IF DEBUG这样的代码
      

  2.   

    没有这种代码。就是我要输出一个word文档的时候,说路径不对。release下就出问题了。
      

  3.   

    你查看一下Build的Output路径。
      

  4.   

    未处理 System.Runtime.InteropServices.COMException
      HelpLink="C:\\Program Files\\Microsoft Office\\OFFICE11\\2052\\wdmain11.chm#24632"
      Message="这不是有效文件名。\n请试用下列方法: \n* 检查路径,确认键入无误。\n* 从文件和文件夹列表中选择文件。"
      Source="Microsoft Word"
      ErrorCode=-2146823136
      StackTrace:
           在 Microsoft.Office.Interop.Word.InlineShapes.AddPicture(String FileName, Object& LinkToFile, Object& SaveWithDocument, Object& Range)
           在 OfficeHelper.WordHelper.AddHeader(String text, String type)
           在 OfficeHelper.WordHelper.DealNode(XmlNode node)
           在 OfficeHelper.WordHelper.CreateDoc(String xmlText, String filename)
           在 Yg.Business.Steps.StepsCalc.CalcStepSeries() 位置 d:\My Documents\Downloads\YgPrject\YgPrject\YgBusiness\Steps\StepsCalc.cs:行号 312
           在 Yg.CAD.FormMain.toolStripButton13_Click(Object sender, EventArgs e) 位置 d:\My Documents\Downloads\YgPrject\YgPrject\程序界面\FormMain.cs:行号 816
           在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
           在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
           在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
           在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
           在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
           在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
           在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
           在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           在 System.Windows.Forms.Control.WndProc(Message& m)
           在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           在 System.Windows.Forms.Application.Run(Form mainForm)
           在 Yg.CAD.Program.Main() 位置 D:\My Documents\Downloads\YgPrject\YgPrject\程序界面\Program.cs:行号 17
           在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           在 System.Threading.ThreadHelper.ThreadStart()
    这个就是错误
      

  5.   

    文件路径的问题别用绝对路径 比方说你放在 程序启动的目录的话用:Application.StartupPath+@"\文件名称.doc";