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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
DanielHollandcommented, Jan 10, 2022

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

0reactions
sepehrtabcommented, Jun 8, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting a Metadata file 'Microsoft.CSharp' could not be ...
And i managed to fix it Basically the cause for that error was using the wrong type of sqlconnection Reworked the code from...
Read more >
Error CS0006 Metadata file .dll could not be found (Solved)
Align and check the build configuration, right click on the solution and select properties. · Unload all the project from the solution and...
Read more >
Metadata file could not be found - Developer Community
I have a solution with about 15 projects. Whenever there is a build error in one project the remaining projects that depend on...
Read more >
FastReport .NET Programmers Manual
When you create a report object in Visual. Studio, necessary lines are automatically written to the configuration file. The WebReport component checks the....
Read more >
Visual Studio 2022 metadata file could not be found
Visual Studio 2022 metadata file could not be found · 1. Right-click on the solution and click Properties. · 2. Click Configuration on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found