Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastReport.Utils.CompilerException: '(0,0): Error CS0006: Metadata file 'Microsoft.CSharp' could not be found #377

Open
DanielHolland opened this issue Jan 7, 2022 · 9 comments

Comments

@DanielHolland
Copy link

DanielHolland commented Jan 7, 2022

I have created a report that works well in the Designer, can be called in the Demo app but can't be incorporated into my application.

I followed the same pattern except I use the "stream" overload for the Report.Load() method and VS throws the exception during the pdfReport.Prepare() method. This issue appears similar to #176 which is marked as resolved.

A working sample is below:

        public static string GenerateReport(Report appReport)
        {
            var template = GetTemplate(appReport.ReportTemplateId);

            var pdfReport = new FastReport.Report();

            RegisteredObjects.AddConnection(typeof(MsSqlDataConnection));

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(template.Markup)))
            {
                pdfReport.Load(stream);
            }
            
            pdfReport.Dictionary.Connections[0].ConnectionString = Globals.ConnectionString;
            pdfReport.Prepare(); 

            // create an instance of HTML export filter
            FastReport.Export.PdfSimple.PDFSimpleExport export = new FastReport.Export.PdfSimple.PDFSimpleExport();
            
            pdfReport.Export(export, ReportFilename);

            return ReportFilename;
        }

Output window:

'MyApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. 
'MyApp.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\MyApp.exe'. Symbols loaded.
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\Utilities.dll'. Symbols loaded.
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\Repository.dll'. Symbols loaded.
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\Domain.dll'. Symbols loaded.
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\EntityFramework.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\EntityFramework.SqlServer.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'Anonymously Hosted DynamicMethods Assembly'. 
The thread 0x4ae4 has exited with code 0 (0x0).
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\Dapper.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Caching\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.Caching.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\FastReport.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\FastReport.Data.MsSql.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\FastReport.OpenSource.Export.PdfSimple.dll'. 
'MyApp.exe' (CLR v4.0.30319: MyApp.exe): Loaded 'D:\Dev\Company\Application\Dev\Repository\UserInterface\bin\Debug\FastReport.Compat.dll'. Module was built without symbols.
Exception thrown: 'FastReport.Utils.CompilerException' in FastReport.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>MyApp.exe</AppDomain><Exception><ExceptionType>FastReport.Utils.CompilerException, FastReport, Version=2022.1.0.0, Culture=neutral, PublicKeyToken=5ceb240df42bf6e8</ExceptionType><Message>(0,0): Error CS0006: Metadata file 'Microsoft.CSharp' could not be found
</Message><StackTrace>   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 Repository.ReportRepository.GenerateReport(Report appReport) in D:\Dev\Company\Application\Dev\Repository\Repository\ReportRepository.cs:line 59
   at MyApp.Reports.List_SelectReport.btn_Select_Click(Object sender, EventArgs e) in D:\Dev\Company\Application\Dev\Repository\UserInterface\Reports\List_SelectReport.cs:line 39
   at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
   at System.Windows.Forms.ListBox.WndProc(Message&amp;amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at MyApp.Program.Main() in D:\Dev\Company\Application\Dev\Repository\UserInterface\Program.cs:line 19</StackTrace><ExceptionString>FastReport.Utils.CompilerException: (0,0): Error CS0006: Metadata file 'Microsoft.CSharp' could not be found

   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 Repository.ReportRepository.GenerateReport(Report appReport) in D:\Dev\Company\Application\Dev\Repository\Repository\ReportRepository.cs:line 59
   at MyApp.Reports.List_SelectReport.btn_Select_Click(Object sender, EventArgs e) in D:\Dev\Company\Application\Dev\Repository\UserInterface\Reports\List_SelectReport.cs:line 39
   at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
   at System.Windows.Forms.ListBox.WndProc(Message&amp;amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp;amp; m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;amp; m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp;amp; msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at MyApp.Program.Main() in D:\Dev\Company\Application\Dev\Repository\UserInterface\Program.cs:line 19</ExceptionString></Exception></TraceRecord>
An unhandled exception of type 'FastReport.Utils.CompilerException' occurred in FastReport.dll
(0,0): Error CS0006: Metadata file 'Microsoft.CSharp' could not be found

Winforms Application.
.Net 4.7.2
FastReport 2022.1.0.0

@DanielHolland
Copy link
Author

I managed to fix this issue by downgrading the version to the same as in the Demo App (2021.4.0.0) and I no longer have the exception

@iadaz
Copy link

iadaz commented May 12, 2022

I have had the same issue with 2022.2.7 and 2022.1.13. I am reluctant to try a much older version and get stuck on it. If I add this line before the Prepare() then the error goes away:

report.RegisterData(Labels, "Labels");

"Labels" is the name of the table inside my data source.

I am replacing the data source's data (Json) with:

connection.JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(Labels);

So the call to RegisterData() would seem to be redundant as the new data has already been pushed into the data source. However without this line the same CS0006 error occurs.

Edit: I am using this from a .net 4.8 command line application with a .net Standard 2.0 library. I wonder if it's a consequence of having .net Standard in the mix.

@larsmaguina
Copy link

I use the library:
FastReport.OpenSource.Data.MsSql - 2021.4.0

I solved it putting to the same version:
FastReport.OpenSource
FastReport.OpenSource.Export.PdfSimple

@nasser-rawda
Copy link

I have solve this by using target framework: .Net 6 instead of using .Net framework 4.6.2. I had to create a new project and choose the "Windows Forms App" and NOT "Windows Forms App (.NET Framework)" to solve this.

@edmundhuang
Copy link

I have solve this by using target framework: .Net 6 instead of using .Net framework 4.6.2. I had to create a new project and choose the "Windows Forms App" and NOT "Windows Forms App (.NET Framework)" to solve this.

Yes, testing same report with table object (even empty table) in data band.
Error in .Net Framework 4.7.2, working in DotNet 6

@sepehrtab
Copy link

Hi, guys,

I am using FastReport Designer to create a report and integrating it into Visual Studio with C#. I am utilizing the VisibleExpression feature in the code to hide a databand if there is no data provided. The expression and preview work fine in the designer, but when I generate it in Visual Studio, I encounter the following error: "FastReport.Utils.CompilerException: '(0,0): Error CS0006: Metadata file 'Microsoft.CSharp' could not be found."

I'm not sure how to resolve this issue, as I have already tried various solutions, such as changing NuGet versions, reinstalling packages, and rebuilding the project. Interestingly, whenever I remove the expression, the report generation works without any errors. Additionally, I've noticed that whenever I attempt to use scripts or expressions in Visual Studio, I encounter the same error if there is something the software doesn't like.

I would greatly appreciate any assistance you can provide.

@Alekarfes
Copy link

Unfortunately we're not aware of an immediate fix, but this issue is on our radar and will be fixed in the future.

@jswolf19
Copy link

jswolf19 commented Mar 13, 2024

This appears to be due to the addition of a reference to Microsoft.CSharp in version 2021.4.14. The comment says it was added for dynamic support. It is added even if the ScriptLanguage of the report is Vb.

The error only seems to occur in reports where the AssemblyDescriptor requires compilation (in my case, the use of VisibleExpression is causing compilation to occur).

If Microsoft.CSharp is not loaded, then the reference is not able to be found, causing an error to occur.

If I add the following code and run it before preparing the report to force Microsoft.CSharp to be loaded into memory, then the error does not occur.

vb

GetType(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).GetType()

c#

typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).GetType();

@nasser-rawda
Copy link

This appears to be due to the addition of a reference to Microsoft.CSharp in version 2021.4.14. The comment says it was added for dynamic support. It is added even if the ScriptLanguage of the report is Vb.

The error only seems to occur in reports where the AssemblyDescriptor requires compilation (in my case, the use of VisibleExpression is causing compilation to occur).

If Microsoft.CSharp is not loaded, then the reference is not able to be found, causing an error to occur.

If I add the following code and run it before preparing the report to force Microsoft.CSharp to be loaded into memory, then the error does not occur.

vb

GetType(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).GetType()

c#

typeof(Microsoft.CSharp.RuntimeBinder.RuntimeBinderException).GetType();

Very big thanks. Indeed that is working for me too now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants