Removing support for script w/ WinForm

Posted by: darin on 21 March 2022, 10:18 am EST

    • Post Options:
    • Link

    Posted 21 March 2022, 10:18 am EST

    According to:

    https://www.grapecity.com/activereportsnet/docs/latest/online/breaking-changes.html

    With this change, scripts with WinForms dependencies must be rewritten in event handlers (for code-based reports), or, in some cases, you may need to load WinForms dependencies manually by using code similar to the following.

    WHY would you do that? We have try/catch in thousands of reports at customers sites that display a MessageBox if there is an issue, and now we have to modify ALL of their RPX files? I just don’t understand why you removed the system files being loaded/accessible.

    In addition, i can’t get your script to work:

    public void ActiveReport_ReportStart()

    {

    this.rpt.AddAssembly(System.Reflection.Assembly.Load(“System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”));

    }

    public void ActiveReport_DataInitialize()

    {

    rpt.Fields.Add("Today");
    rpt.Fields["Today"].Value = System.DateTime.Now.ToString("MMMM d, yyyy h:mm tt");
    MessageBox.Show("A");
    

    }

    When run:

    Report creation failed - report script compile error on line 11: The name ‘MessageBox’ does not exist in the current context.

  • Posted 22 March 2022, 5:48 am EST

    Hi Darin,

    Apologies for the inconvenience caused. I was able to replicate your issue on my end. I have escalated this issue to the development team and will revert back to you once I have any information from them.(For internal use-AR-28482)

  • Posted 22 March 2022, 7:04 am EST

    Hi Darin,

    The code in the documentation page Breaking Changes seems to be incorrect. I have shared a sample application to show how you can reference System.Windows.Forms in your Report.

    >> WHY would you do that?

    We have removed dependency for WinForms from the assembly as it is not necessary. So scripts does not have WinForms reference too (automatically).

    Although it could be possible to restore the dependency for .NET Framework scripts (only for GDI mode) such changes may cause problems to customers if they decide to migrate to .NET Core.

    Regards,

    Akshay

    AssemblyReferenceTestXML.zip

  • Posted 22 March 2022, 7:39 am EST

    That worked excellently - thank you.

    So i can use that logic to load any assembly i want, including our own - correct?

  • Posted 22 March 2022, 8:18 am EST

    I have added an addassembly for our own DLL that we want to use via scripting. The addassembly loads correctly (i have confirmed this by mis-typing and it errors), but when attempting to run the program i get the error that it can’t find the program (possible missing assembly).

    The only thing i can think of is all of our programs, and this DLL that i am loading, is compiled with .NET 4.8. Is there an issue with the script compiler and .NET4.8?

    We are using AR16.

  • Posted 22 March 2022, 10:27 am EST

    I got this all working. I believe it is due to some DLL being strong named and others not.

    All good.

  • Posted 23 March 2022, 2:56 am EST

    Hi Darin,

    I am glad you were able to resolve your issue.

    Thanks for sharing the solution with us. It’ll be helpful for others who might be trying to do something similar.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels