c# 報表

场景:C#水晶報表报表解决方法

C#水晶報表报表
各位高手:
  我写了一个水晶报表窗体,采用动态反射代用这个窗体,第一次可以打开,当我打开后导出EXCEL后关闭,在打开这个水晶报表就报错,“调用的目标发生了异常”



有关调用实时(JIT)调试而不是此对话框的详细信息,
请参见此消息的结尾。

************** 异常文本 **************
System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.IO.FileNotFoundException: 未能加载文件或程序集“file:///C:\Documents and Settings\jhuihuang\桌面\RportFm.dll”或它的某一个依赖项。系统找不到指定的文件。
  在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
  在 System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
  在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
  在 System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
  在 System.Reflection.Assembly.LoadFrom(String assemblyFile)
  在 DllClass.SystemVoid.ReportFmShow(String FromID, String HeaderWhere, String DataWhere, String FooterWhere)
  --- 内部异常堆栈跟踪的结尾 ---
  在 System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
  在 System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
  在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
  在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  在 System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
  在 BME08.BME08.ClassVoid(String Classname, String methods, Object[] parameters, Type[] DataType)
  在 BME08.BME08.Print()
  在 BME08.BME08.ToolButton_TspClick(Object sender, EventArgs e)
  在 ButtonToolBar.UserToolBar.TspPrint_Click(Object sender, EventArgs e)
  在 System.Windows.Forms.ToolStripSplitButton.OnButtonClick(EventArgs e)
  在 System.Windows.Forms.ToolStripSplitButton.OnMouseUp(MouseEventArgs 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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)




------解决方案--------------------
不是告诉你了,找不到RportFm.dll
路径有问题,保存之后,Environment.CurrentDirectory变了
------解决方案--------------------
未能加载文件或程序集“file:///C:\Documents and Settings\jhuihuang\桌面\RportFm.dll”或它的某一个依赖项。系统找不到指定的文件。

主要原因还是上面没有成功加载RportFm.dll,你把这个dll放到某个盘中,用绝对路径LoadForm(路径)试试.
如果加载成功了,为了确保你的这个dll不改变路径,引用到当前项目中,改LoadForm(路径)为LoadForm("RportFm.dll")即可.