Page 1 of 1

Bad IL format exception

Posted: Fri Mar 20, 2015 2:23 pm
by Lotte
Hi,

A customer is running our software (Windows Forms with StimulReports 2014.1.1900.0) and gets a "Bad IL Format" exception when trying to print a report or open it in the report viewer control for windows forms.

I'm using your reporting tools already for several years and have never encountered this exception.

Can you point us in the right direction which might be the problem?

Here is the stacktrace:

InnerException message : Could not load file or assembly '0 bytes loaded from System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Begin StackTrace
------------------------------------------
at System.Reflection.RuntimeAssembly.nLoadImage(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, SecurityContextSource securityContextSource)
at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore, Evidence securityEvidence)
at Microsoft.CSharp.CSharpCodeGenerator.FromFileBatch(CompilerParameters options, String[] fileNames)
at Microsoft.CSharp.CSharpCodeGenerator.FromSourceBatch(CompilerParameters options, String[] sources)
at Microsoft.CSharp.CSharpCodeGenerator.System.CodeDom.Compiler.ICodeCompiler.CompileAssemblyFromSourceBatch(CompilerParameters options, String[] sources)
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource(CompilerParameters options, String[] sources)
at Stimulsoft.Base.StiCompiler.Compile(String textToCompile, String outputAssembly, LanguageType languageType, StiOutputType outputType, String[] referencedAssemblies, List`1 resources)
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile()
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSingleReport(StiReport masterReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
at Stimulsoft.Report.StiReport.Render()
at BIG.Products.GUI.ProductViewer.frmPrint.ShowReportPreview(StiReport report)
at BIG.Products.GUI.ProductViewer.frmPrint.PrintReport(Boolean showPreview)
at BIG.Products.GUI.ProductViewer.frmPrint.btnPreview_Click(Object sender, EventArgs e)
------------------------------------------
End StackTrace

InnerException message : Bad IL format.
Begin StackTrace

Hope someone knows what is the cause of this issue?

Thanks.

Re: Bad IL format exception

Posted: Mon Mar 23, 2015 6:43 am
by HighAley
Hello.

Sorry, but we don't know why do you get this error.
Please, try to read answers on the Why return BAD IL FORMAT to load assembly from wcf service? question.
If this does not help, please, send us a sample project which reproduces the issue.

Thank you.

Re: Bad IL format exception

Posted: Mon Mar 23, 2015 9:53 am
by Lotte
Hi,

As you pointed out in your link, I assumed that loading the dynamically generated assembly gives the error.

However, it happens when stimulsoft generates the assembly from the .mrt file. I guess the Stimulsoft .CSharpCodeGenerator.FromFileBatch generates code that can't be read by the consecutive Assembly.Load. Does the generator store the generated assembly in a temporary folder where there could be access issues or something? What does the code generator need as requirements to function properly and make the assembly work?

Re: Bad IL format exception

Posted: Mon Mar 23, 2015 1:21 pm
by HighAley
Hello.

Yes, there could be an access problem. You could change the path to compiled report by adding a parameter to the Compile method.

Code: Select all

 report.Compile(compiledReportFile);
You could solve the issue by specifying a folder that application has access to.

Thank you.

Re: Bad IL format exception

Posted: Mon Mar 30, 2015 7:42 am
by Lotte
Thank you for the information.

However the affected user reported that the issue was solved. He thinks it was solved after he updated the .NET framework from 4.5.1 to 4.5.2 and rebooted the server in the process.

I don't know if the server reboot or the .NET framework update did it, but for now the issue is solved.

Re: Bad IL format exception

Posted: Mon Mar 30, 2015 7:44 am
by Alex K.
Hello,

We are always glad to help you!
Let us know if you need any additional help.

Thank you.