Loading all referenced assemblies error - when scripting used

Posted by: mlk20 on 15 January 2020, 6:10 am EST

    • Post Options:
    • Link

    Posted 15 January 2020, 6:10 am EST

    Hi,

    We are having problems when generating Section Reports that use Scripting.

    We have an assembly - lets call it ParentAssembly.dll - that has some referenced assemblies - lets call them ChildAssembly1.dll, ChildAssembly2.dll etc…

    We have two configurations of our software:

    “Complete” - We deploy all the assemblies to the client: ParentAssembly.dll, ChildAssembly1.dll, ChildAssembly2.dll etc…

    and

    “Partial” - We deploy NOT ALL of the assemblies to the client: e.g. ParentAssembly.dll and ChildAssembly1.dll only (ChildAssembly2.dll and other assemblies are not deployed).

    We generate Section Reports from ParentAssembly.dll.

    Now it seems that:

    1. When we generate a report without a scripts then it works in both “Complete” and “Partial” configurations of our software.
    2. When we generate a report WITH SCRIPTS then it works in “Complete” configuration, BUT IT DOES NOT WORK in “Partial” configuration.

    The error that is generated looks like:

    Could not load file or assembly ‘XXX, Version=YYY, Culture=neutral, PublicKeyToken=ZZZ’ or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))

    Callstack:

    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

    at System.AppDomain.Load(AssemblyName assemblyRef)

    at GrapeCity.ActiveReports.DDScripting.b__f(AssemblyName asmName)

    at System.Linq.Enumerable.WhereSelectArrayIterator

    2.MoveNext()    at System.Linq.Enumerable.WhereEnumerableIterator
    1.MoveNext()

    at System.Collections.Generic.HashSet
    1.UnionWith(IEnumerable
    1 other)

    at GrapeCity.ActiveReports.DDScripting.Compile()

    at GrapeCity.ActiveReports.DDScripting.#Szb(String methodName, Object parameters, Boolean& success)

    at GrapeCity.ActiveReports.SectionReport.#izb()

    at GrapeCity.ActiveReports.SectionReport.#1yb(Boolean bDelayedInit)

    at GrapeCity.ActiveReports.SectionReport.Run(Boolean syncDocument)

    By digging into Active Reports internals it looks like when preparing data for Compile() method you try to load all referenced libraries for the current assembly and when it’s not possible then you propagate the error down the application stack and the report generation fails:

    private static IEnumerable #ViV(Assembly assembly)

    {

    return from location in assembly.GetReferencedAssemblies().Select(delegate(AssemblyName asmName)

    {

    try

    {

    return AppDomain.CurrentDomain.Load(asmName).Location;

    }

    catch

    {

    throw;

    }

    })

    where !string.IsNullOrEmpty(location)

    select location;

    }

    I understand this approach and it looks logical but it fails our “Partial” deployment strategy. (ChildAssembly2.dll will NEVER be loaded in our application as there are no “entry points” in the application that would trigger loading ChildAssembly2.dll - It’s only Active Reports scripting engine that is trying to load this assembly).

    Can you provide some workaround for this problem or introduce some “property” that would allow changing current scripting engine behavior (e.g. to return not loaded assemblies in some property, or to give a property that would allow assemblies that should NOT be loaded) ?

    Thank you,

    Krupek

  • Posted 15 January 2020, 5:18 pm EST

    Hello Krupek,

    If my understanding is right, you are loading both assemblies in the report using the “AddScriptReference” method of the report. Can’t you use the “Conditional compilation symbols” to create the two ParentAssembly? You can add the AddScriptReference code for the second class library in the"Conditional compilation symbols". After that, chose the desired library according to the installation type.

    Also, you can change the script using the “Script” property of the report at runtime.

    If my understanding is incorrect, please explain in a little bit detail.

    Thanks,

    Mohit

  • Posted 15 January 2020, 7:39 pm EST

    Hi,

    Your understanding is incorrect.

    This is how Visual Studio project structure looks like:

    ParentAssembly.dll:

    References:

    - ChildAssembly1.dll

    - ChildAssembly2.dll

    - …

    What I described has nothing to do with AddScriptReference() method. I don’t use this method at all.

    It’s Active Reports scripting engine that internally tries to load all the assemblies that are referenced under current assembly.

    Loading occurs in the body of GrapeCity.ActiveReports.DDScripting.Compile() method.

    Thank you.

  • Posted 15 January 2020, 10:00 pm EST

    Hi,

    See also attached project where error can be reproduced.

    Scenario 1. Open application. Click “Generate Report”. Report is generated correctly.

    Scenario 2. Open application. First click “Delete ChildAssembly02.dll” and then click “Generate Report”. Report is NOT generated - Exception occurs becuase ChildAssembly02.dll cannot be loaded.ARScriptingError.zip

  • Posted 16 January 2020, 5:25 pm EST

    Hello,

    Thanks for the sample. It is very helpful for us.

    I am able to receive the error in AR11. However, I am not able to reproduce the error in AR13/AR14. Could you please upgrade to the latest version as AR11 is out of development and we don’t support it anymore.

    You can download the same from the following link:

    https://www.grapecity.com/download/activereports

    https://www.grapecity.com/activereports/docs/v14/online/install-activereports.html

    Also, please refer to the following link for the breaking changes and new features in AR14.

    https://www.grapecity.com/activereports/docs/v14/online/whats-new.html

    https://www.grapecity.com/activereports/docs/v14/online/breaking-changes.html

    Thanks,

    Mohit

  • Posted 16 January 2020, 8:41 pm EST

    Hi,

    Can you explain why the problem is not observed in AR13/AR14? What have been changed? Don’t you load referenced assemblies anymore?

    Thank you.

  • Posted 19 January 2020, 6:08 pm EST

    Hello Krupek,

    I am escalated this to our development team(278163) for the detail information on this and will inform you once I get any information from them.

    Thanks,

    Mohit

  • Posted 27 January 2020, 12:06 am EST

    Hi,

    Any update to my questions?

    Thank you.

  • Posted 27 January 2020, 1:42 am EST

    Hello,

    AR13 scripts started to be executed in a separate domain that’s why this issue is not reproducible in AR13/AR14.

    Thanks,

    Mohit

  • Posted 27 January 2020, 11:41 pm EST

    Hi,

    Is it really related to the domain that is used? I think it is rather related to the code of private static IEnumerable #ViV(Assembly assembly) method which rethrows the exception that is thrown by the invocation of AppDomain.CurrentDomain.Load(asmName).Location instruction.

    Have you change the code so the exception is not retrhown down the application stack?

    Thank you.

  • Posted 28 January 2020, 7:56 pm EST

    Hello Krupek,

    I have forwarded this to our development team for more information on this and will inform you once I get any updates from them.

    Thanks,

    Mohit

  • Posted 30 January 2020, 9:02 pm EST

    Hello,

    This is only related to the domain. The code which loads the assembly has not changed for 6 years.

    Thanks,

    Mohit

Need extra support?

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

Learn More

Forum Channels