In the project, it is normal to start report with from2, and report cannot be started with from1. log:
13:11:06
Startgeneratereporttask: system. runtime. interopservices. sehexception: An exception occurs for the external component.
At system. Windows. Forms. unsafenativemethods. dispatchmessagew (MSG & MSG)
At system. Windows. Forms. componentmanager. system. Windows. Forms. unsafenativemethods + imsocomponentmanager. fpushmessageloop (int32 dwcomponentid, int32 reason, int32 pvloopdata)
At system. Windows. Forms. threadcontext. runmessageloopinner (int32 reason, applicationcontext context)
At system. Windows. Forms. threadcontext. runmessageloop (int32 reason, applicationcontext context)
At system. Windows. Forms. application. rundialog (Form)
At system. Windows. Forms. Form. showdialog (iwin32window owner)
At system. Windows. Forms. Form. showdialog ()
At ZTE. CCG. Report. reportcontroller. startgeneratereporttask (string contractheader) in ***/report/quotationgenerationmodule/reportcontroller. CS: Line 469
Since from2 and report are developed by the same person, it is no problem to start reportcontroller directly, but we can start reportcontroller in the same way. At first, we thought there was a problem with our program. The trace code found that this exception was not fixed and it was hard to determine that there was a problem.
Although an exception occurs in the external component, no other third-party applications can be called in the application.
Compared with form1 and form2, we found that:
Form1:
[Stathread]
Public static void main (string [] ARGs)
{
// Lots of code...
// It's same of the Code posted on form2.
}
Form2:
[Stathread]
Public static void main (string [] ARGs)
{
Application. enablevisualstyles ();
Application. doevent ();
// Lots of code...
}
Change the code in form1 to continue execution. The program runs normally without any errors.
Cancel the two statements and the error will appear again.
After querying msdn, we found that:
"This method enables the Windows XP visual style of the application. If the controls and Operating Systems Support visual styles, the controls are drawn in this style. To enablevisualstyles take effect, you must call it before creating any control in the application. enablevisualstyles is usually the first line of the main function. When you call enablevisualstyles, you can enable the visual style without a separate list.
For controls that support the flatstyle attribute, make sure that the flatstyle attribute is set to the flatstyle. System value ."
Search for flatstyle and find that many custom controls in the report are written as follows:
This. xxxcontrolname. flatstyle = system. Windows. Form. flatstyle. system;
That is to say, the control is the system style used. When using the system style, you must tell the system to enable the virtual style.
Otherwise, the preceding application exception may occur.
To verify this conjecture, comment out the following in from1:
Application. enablevisualstyles ();
Application. doevent ();
Sure enough, the program encountered an exception during execution.
After searching on Google, I found that many of the above similar exceptions are more or less mentioned in the XP style.
Related Resources:
1). NET 1.1 framework fix:
Http://support.microsoft.com/Default.aspx? Kbid = 899511
2) solution in vs2005:
Http://support.microsoft.com/kb/897298
Some information about the Microsoft msdn Forum:
Http://forums.microsoft.com/MSDN/ShowPost.aspx? Postid = 48878 & siteid = 1
Http://forums.microsoft.com/MSDN/ShowPost.aspx? Postid = 388724 & siteid = 1