FastReport Core and AssemblyLoadContext

hallo,

i have copy the samples from dotnet core https://github.com/dotnet/samples

and want to implement a plugin for this https://github.com/dotnet/samples/tree/master/core/extensions/AppWithPlugin

example plugin in project. This works all fine. i can load the plugin. but at running the plugin i have a exception. can anyone help ?



Loading commands from: C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\report.dll

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\report.dll into the PluginLoadCont

ext

report, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

-- EtikettenDrucker --

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\intern.dll into the PluginLoadCont

ext

intern, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Etiketten werden erzeugt...

stb.dat X:/sf/db/shost/40855keller/stb.dat

Reportdatei frx C:/workspace_qt/sup/CADKunde/cm_cfg/makro/local/massivbau/frx/etiketten_12x9.frx

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\FastReport.dll into the PluginLoad

Context

FastReport, Version=2020.2.0.0, Culture=neutral, PublicKeyToken=a600f62542d33eb9

stb.xml X:/sf/db/shost/40855keller/stb.xml

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\runtimes\win\lib\netcoreapp3.0\Sys

tem.Drawing.Common.dll into the PluginLoadContext

System.Drawing.Common, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\Microsoft.CodeAnalysis.dll into th

e PluginLoadContext

Microsoft.CodeAnalysis, Version=3.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

Loading assembly C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\bin\Debug\netcoreapp3.1\Microsoft.CodeAnalysis.CSharp.dll

into the PluginLoadContext

Microsoft.CodeAnalysis.CSharp, Version=3.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

System.IO.FileNotFoundException: Could not load file or assembly 'FastReport, Version=2020.2.0.0, Culture=neutral, PublicKeyToken=a600f62542d33eb9'. Das System kann die ange

gebene Datei nicht finden.

File name: 'FastReport, Version=2020.2.0.0, Culture=neutral, PublicKeyToken=a600f62542d33eb9'

  at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)

  at System.Reflection.RtFieldInfo.InitializeFieldType()

  at System.Reflection.RtFieldInfo.InitializeInvocationFlags()

  at System.Reflection.RtFieldInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)

  at System.Reflection.FieldInfo.SetValue(Object obj, Object value)

  at FastReport.Code.AssemblyDescriptor.InitField(String name, Object c)

  at FastReport.Code.AssemblyDescriptor.InitFields()

  at FastReport.Code.AssemblyDescriptor.InitInstance(Object instance)

  at FastReport.Code.AssemblyDescriptor.InternalCompile()

  at FastReport.Code.AssemblyDescriptor.Compile()

  at FastReport.Report.Compile()

  at FastReport.Report.Prepare(Boolean append)

  at FastReport.Report.Prepare()

  at report.EtikettenDrucker.GenerateReport() in C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\EtikettenDrucker.cs:line

207

  at report.EtikettenDrucker.Program(List`1 param) in C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\EtikettenDrucker.cs:

line 272

  at report.EtikettenDrucker.Execute() in C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\report\EtikettenDrucker.cs:line 299

  at AppWithPlugin.Program.Main(String[] args) in C:\Users\sf\Documents\Projects\dotnet-samples\samples-master\core\extensions\AppWithPlugin\AppWithPlugin\Program.cs:line 6

3

Comments

  • Now i have solved the problem by fixing the FastReport Source OpenSource. The problem only occurs if you have expressions or other things in report that triggeres the InternalCompile methode.

    The fix is in file

    FastReportOpenSource\FastReport.Base\Code\AssemblyDescriptor.cs - Method InternalCompile

    i replaced CodeDom Compiler with roslyn Compiler but the trick is who to load the compiled assembly

    assembly = AssemblyLoadContext.CurrentContextualReflectionContext.LoadFromStream(asm);

    after all i can run FastReport as a Plugin in AssemblyLoadContext with EnterContextualReflection but i can not unload the plugin and i do not know why ?


  • i have made an other change to the file und little bit of cleanup.

    1. AddFastReportAssemblies creates MetadataReference directly

    2. AddFastReportAssemblies creates MetadataReference from in memory assemblies (with no location)

    3. comment the old method InternalCompile

    4. if no AssemblyLoadContext.CurrentContextualReflectionContext use AssemblyLoadContext.Default to load assembly from stream


Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.