Reflection issue: Could not load file or assembly
Posted: Fri Aug 24, 2012 11:36 am
Hallo Support,
I have an assembly/reflection issue for which I cannot find a solution, despite several hours of trying. We are using Stimulsoft.Report.dll (v2.0.50727) and Stimulsoft.Base.dll (v2.0.50727) in our c# code with .net Framework 4. Up to now, everything has been server-side (in .net) and has worked fine. We now wish to provide an offline-version of our product which means that everything will be installed on the client. The calling program is silverlight which must call the ReportGenerator .net class which then calls the Stimulsoft dlls to produce the pdf. Since silverlight cannot call .net directly we have decided to use a COM+ service, even if this sounds a bit old-fashioned.
So I now have a silverlight test program which calls the COM+ server dll, which in turn call my ReportGenerator, passing it the data it requires to produce a report. My ReportGenerator class creates the StiReport as usual and for a simple report, everything works fine: the pdf is created. The problem arises when I have a main report with sub-reports. Here I receive a "Could not load file or assembly" error (see below). On debugging, it seems that Stimulsoft.Base is calling methods in Stimulsoft.Report by reflection. When I call AppDomain.CurrentDomain.GetAssemblies() I can see that both dlls have been loaded. However, I also see that the event AppDomain.CurrentDomain.TypeResolve is being called many times. As I understand it, this event is only called when an attempt is made to call a method by reflection and the method or its assembly cannot be loaded. Here, I see that the base assembly is calling methods in the Stimulsoft.Report assembly.
I have tried re-loading the assembly from within the event and returning it. Unfortunately, this makes no difference and I end up with this error:
Loader exception
{"Could not load file or assembly 'Stimulsoft.Report, Version=2012.2.1302.0, Culture=neutral, PublicKeyToken=ebe6666cba19647a' or one of its dependencies. The system cannot find the file specified.":"Stimulsoft.Report, Version=2012.2.1302.0, Culture=neutral, PublicKeyToken=ebe6666cba19647a"}
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Stimulsoft.Report.StiReport.GetReportsFromAssembly(Assembly assembly)
at Stimulsoft.Report.StiReport.GetReportFromAssembly(Assembly assembly)
at Stimulsoft.Report.StiReport.CreateInstance()
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile(StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile()
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSubReports(StiReport ownerReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress, Int32 fromPage, Int32 toPage)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress)
at MM.Office.Services.ReportGenerator.ReportEngine.MergeReports()
Step into: Stepping over non-user code 'Stimulsoft.Base.StiCompiler.Compile'
Step into: Stepping over non-user code 'Stimulsoft.Report.StiReport.Compile'
A first chance exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in Stimulsoft.Report.dll
----------------------
It looks as though StiTypeFinder.GetType is doing the reflection call using AppDomain.CurrentDomain.GetAssemblies().
Have you had this issue before and do you have any idea what I can do about it?
Thanks and regards,
John Kitching
I have an assembly/reflection issue for which I cannot find a solution, despite several hours of trying. We are using Stimulsoft.Report.dll (v2.0.50727) and Stimulsoft.Base.dll (v2.0.50727) in our c# code with .net Framework 4. Up to now, everything has been server-side (in .net) and has worked fine. We now wish to provide an offline-version of our product which means that everything will be installed on the client. The calling program is silverlight which must call the ReportGenerator .net class which then calls the Stimulsoft dlls to produce the pdf. Since silverlight cannot call .net directly we have decided to use a COM+ service, even if this sounds a bit old-fashioned.
So I now have a silverlight test program which calls the COM+ server dll, which in turn call my ReportGenerator, passing it the data it requires to produce a report. My ReportGenerator class creates the StiReport as usual and for a simple report, everything works fine: the pdf is created. The problem arises when I have a main report with sub-reports. Here I receive a "Could not load file or assembly" error (see below). On debugging, it seems that Stimulsoft.Base is calling methods in Stimulsoft.Report by reflection. When I call AppDomain.CurrentDomain.GetAssemblies() I can see that both dlls have been loaded. However, I also see that the event AppDomain.CurrentDomain.TypeResolve is being called many times. As I understand it, this event is only called when an attempt is made to call a method by reflection and the method or its assembly cannot be loaded. Here, I see that the base assembly is calling methods in the Stimulsoft.Report assembly.
I have tried re-loading the assembly from within the event and returning it. Unfortunately, this makes no difference and I end up with this error:
Loader exception
{"Could not load file or assembly 'Stimulsoft.Report, Version=2012.2.1302.0, Culture=neutral, PublicKeyToken=ebe6666cba19647a' or one of its dependencies. The system cannot find the file specified.":"Stimulsoft.Report, Version=2012.2.1302.0, Culture=neutral, PublicKeyToken=ebe6666cba19647a"}
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Stimulsoft.Report.StiReport.GetReportsFromAssembly(Assembly assembly)
at Stimulsoft.Report.StiReport.GetReportFromAssembly(Assembly assembly)
at Stimulsoft.Report.StiReport.CreateInstance()
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate, Object standaloneReportType)
at Stimulsoft.Report.StiReport.Compile(String path, Stream stream, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType, Boolean autoCreate)
at Stimulsoft.Report.StiReport.Compile(String path, StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile(StiOutputType outputType)
at Stimulsoft.Report.StiReport.Compile()
at Stimulsoft.Report.Engine.StiReportV2Builder.RenderSubReports(StiReport ownerReport, StiRenderState renderState)
at Stimulsoft.Report.StiReport.RenderReport(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState, StiGuiMode guiMode)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress, Int32 fromPage, Int32 toPage)
at Stimulsoft.Report.StiReport.Render(Boolean showProgress)
at MM.Office.Services.ReportGenerator.ReportEngine.MergeReports()
Step into: Stepping over non-user code 'Stimulsoft.Base.StiCompiler.Compile'
Step into: Stepping over non-user code 'Stimulsoft.Report.StiReport.Compile'
A first chance exception of type 'System.Reflection.ReflectionTypeLoadException' occurred in Stimulsoft.Report.dll
----------------------
It looks as though StiTypeFinder.GetType is doing the reflection call using AppDomain.CurrentDomain.GetAssemblies().
Have you had this issue before and do you have any idea what I can do about it?
Thanks and regards,
John Kitching