Hiển thị các bài đăng có nhãn CSharp. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn CSharp. Hiển thị tất cả bài đăng

Thứ Tư, 2 tháng 11, 2016

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception


Vb.net tutorial for beginners - This lessons will show you how to fix some error in Crystal Report Applications Development. When you have published your simple application that use vb.net or C#.net using installShield.

Some error will be like

An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
The error is : The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception

Solutions 1:

When a static constructor throws an exception, it is wrapped inside a TypeInitializationException. You need to check the exception object's InnerException property to see the actual exception.

In a staging / production environment (where you don't have Visual Studio installed), you'll need to either:
  1. Trace/Log the exception and its InnerException (recursively): Add an event handler to the AppDomain.UnhandledException event, and put your logging/tracing code there. Use System.Diagnostics.Debug.WriteLine for tracing, or a logger (log4net, ETW). DbgView (a Sysinternals tool) can be used to view the Debug.WriteLine trace.
  2. Use a production debugger (such as WinDbg or NTSD) to diagnose the exception.
  3. Use Visual Studio's Remote Debugging to diagnose the exception (enabling you to debug the code on the target computer from your own development computer).

Solutions 2 :

If you are installing on a 64-bit machine, make sure the application properties under the Build tab have "Any CPU" as the platform target, and unselect the check box for "Prefer 32-bit" if you have the option. Crystal is very touchy about 32/64 bit assemblies, and makes some pretty counterintuitive assumptions which are very difficult to troubleshoot.

Solution 3 :

  1. i set x86 for my application, then i set x64 for my setup application
  2. Prerequisite: i Placed the supporting CR runtime file CRRuntime_32bit_13_0_10.msi, CRRuntime_64bit_13_0_10.msi in the following directory C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Reports for .NET Framework 4.0
  3. Include merge module file to the setup project. Here is version is not serious thing because i use 13.0.10 soft, 13.0.16 merge module file File i included: CRRuntime_13_0_16.msm This file is found one among the set msm files.
While installing this Merge module will add the necessary dll in the following dir C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet

dll file version will not cause any issues.

In your developer machine you confirm it same.

List Video Tutorial VB.NET For beginners



List Video tutorials C# for Beginners



references :
http://stackoverflow.com/questions/16658300/the-type-initializer-for-crystaldecisions-crystalreports-engine-reportdocument

http://stackoverflow.com/questions/2866831/an-error-occurred-creating-the-form-see-exception-innerexception-for-details-t

See you next lessons .....

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception


Vb.net tutorial for beginners - This lessons will show you how to fix some error in Crystal Report Applications Development. When you have published your simple application that use vb.net or C#.net using installShield.

Some error will be like

An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object.
The error is : The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception

The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception

Solutions 1:

When a static constructor throws an exception, it is wrapped inside a TypeInitializationException. You need to check the exception object's InnerException property to see the actual exception.

In a staging / production environment (where you don't have Visual Studio installed), you'll need to either:
  1. Trace/Log the exception and its InnerException (recursively): Add an event handler to the AppDomain.UnhandledException event, and put your logging/tracing code there. Use System.Diagnostics.Debug.WriteLine for tracing, or a logger (log4net, ETW). DbgView (a Sysinternals tool) can be used to view the Debug.WriteLine trace.
  2. Use a production debugger (such as WinDbg or NTSD) to diagnose the exception.
  3. Use Visual Studio's Remote Debugging to diagnose the exception (enabling you to debug the code on the target computer from your own development computer).

Solutions 2 :

If you are installing on a 64-bit machine, make sure the application properties under the Build tab have "Any CPU" as the platform target, and unselect the check box for "Prefer 32-bit" if you have the option. Crystal is very touchy about 32/64 bit assemblies, and makes some pretty counterintuitive assumptions which are very difficult to troubleshoot.

Solution 3 :

  1. i set x86 for my application, then i set x64 for my setup application
  2. Prerequisite: i Placed the supporting CR runtime file CRRuntime_32bit_13_0_10.msi, CRRuntime_64bit_13_0_10.msi in the following directory C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Reports for .NET Framework 4.0
  3. Include merge module file to the setup project. Here is version is not serious thing because i use 13.0.10 soft, 13.0.16 merge module file File i included: CRRuntime_13_0_16.msm This file is found one among the set msm files.
While installing this Merge module will add the necessary dll in the following dir C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet

dll file version will not cause any issues.

In your developer machine you confirm it same.

List Video Tutorial VB.NET For beginners



List Video tutorials C# for Beginners



references :
http://stackoverflow.com/questions/16658300/the-type-initializer-for-crystaldecisions-crystalreports-engine-reportdocument

http://stackoverflow.com/questions/2866831/an-error-occurred-creating-the-form-see-exception-innerexception-for-details-t

See you next lessons .....

Chủ Nhật, 11 tháng 9, 2016

C# & VB.NET Context Menu Right Click Copy, Cut, Paste Functions


C# .NET for beginners : How to add Context Menu Right Click with Copy, Cut, and Paste Functions in a TextBox or RichTextBox using C# and VB.NET?

Create Context Menu Right in C#

Add Copy, Cut, Paste Function

        void CutAction(object sender, EventArgs e) {
            richTextBox1.Cut();
        }

        void CopyAction(object sender, EventArgs e) {
            Clipboard.SetData(DataFormats.Rtf, richTextBox1.SelectedRtf);
        }

        void PasteAction(object sender, EventArgs e) {
            if (Clipboard.ContainsText(TextDataFormat.Rtf)) {
                richTextBox1.SelectedRtf = Clipboard.GetData(DataFormats.Rtf).ToString();
            }
            richTextBox1.Text = Clipboard.GetText();
        }

Next Add this source code on Event of a TextBox or RichTextBox

        private void richTextBox2_MouseDown(object sender, MouseEventArgs e) {
            if (e.Button == MouseButtons.Right) {
                ContextMenu contextMenu = new System.Windows.Forms.ContextMenu();
                MenuItem menuItem = new MenuItem("Cut");
                menuItem.Click += new EventHandler(CutAction);
                contextMenu.MenuItems.Add(menuItem);
                menuItem = new MenuItem("Copy");
                menuItem.Click += new EventHandler(CopyAction);
                contextMenu.MenuItems.Add(menuItem);
                menuItem = new MenuItem("Paste");
                menuItem.Click += new EventHandler(PasteAction);
                contextMenu.MenuItems.Add(menuItem);
                richTextBox1.ContextMenu = contextMenu;
            }
        }

Create context Menu Right in VB.NET

Add ContextMenuStrip component to your form, then add some items to this ContextMenuStrip like "Copy","CUT" and "Paste".

C# & VB.NET Context Menu Right Click Copy, Cut, Paste Functions

next add this source code :

Private Sub CutToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles CutToolStripMenuItem.Click
   RichTextBox1.Cut()
End Sub

Private Sub CopyToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles CopyToolStripMenuItem.Click
   RichTextBox1.Copy()
End Sub

Private Sub PasteToolStripMenuItem_Click(sender As Object, e As EventArgs) _
Handles PasteToolStripMenuItem.Click
   RichTextBox1.Paste()
End Sub

See you next lessons ....