Hello,
The migration from Framework to Net 8.0 went smoothly, but it works well.
The only major error for me occurred when producing a report with Microsoft ReportViewer.
Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing.
Microsoft.Reporting.DefinitionInvalidException: The definition of the report '' is invalid.
Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: An unexpected error occurred in Report Processing.
System.TypeLoadException: Method 'GetHashCode' in type 'Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions' from assembly 'Microsoft.CodeAnalysis.VisualBasic, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
Problem:
the Microsoft.CodeAnalysis dll in the Autocad 2025 folder is version 4.0.0
Solution:
Replace Microsoft.CodeAnalysis version 4.0.0.0 with version 4.8.0.0, and add Microsoft.CodeAnalysis.VisualBasic, Version=4.8.0.0.
It seems that when Autocad 2025 is run, this has no influence, but I don't like this replacement very much.
I've tried for a long time to load a compatible dll or something without success. I have no experience in this kind of code.
I have no experience with this type of code.
I am attaching a Test report.
Thank you in advance for your help...
*** Translated with www.DeepL.com/Translator (free version) ***
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
I do not think you need to bother replacing Microsoft.CodeAnalysis dll at all. It is dependency of the ReportViewerCore.WinForms Package, which comes with many other dependencies. As long as you make sure these dependencies are outputted into the same folder as the plugin DLL with either
<CopyLocalLockAssemblies>true<CopyLocalLockAssemblies/>
or
<EnableDynamicLoading>true</EnableDynamicLoading>
Since you also use System.Data.OldDb package, you MUST ALSO add
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
I did a quick test with a static report (i.e. no data source, no database connection) to simply prove the ReportViewerCore.WinForms package load OK with AutoCAD 2025.
This is the report design (*.rdlc file) with only a static TextBox:
the Report1.rcdl file is set its "Copy to output directory" property to "Copy if newer"
This is the WinForm's code behind:
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MsDataReport
{
public partial class ReportDialog : Form
{
private ReportViewer _reportViewer;
public ReportDialog()
{
InitializeComponent();
_reportViewer=reportViewer1 as ReportViewer;
_reportViewer.Dock = DockStyle.Fill;
}
private void ReportDialog_Load(object sender, EventArgs e)
{
_reportViewer.ProcessingMode = ProcessingMode.Local;
this.Controls.Add( _reportViewer );
using (var fs=new FileStream("Report1.rdlc", FileMode.Open))
{
_reportViewer.LocalReport.LoadReportDefinition(fs);
}
_reportViewer.RefreshReport();
}
}
}
Then this is the command method to open the report in AutoCAD:
[CommandMethod("ShowReport")]
public static void RunReport()
{
var oked = false;
using (var dlg = new ReportDialog())
{
CadApp.ShowModalDialog(CadApp.MainWindow.Handle, dlg, false);
}
}
This is the dialog form showing in AutoCAD:
If I have proper data source setup, it should show data report content accordingly.
This is the output folder where the plugin dll is:
I think the error you have is probably because you did not have
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
in project file.
BTW, if you are to do .NET API programming for AutoCAD 2025 or later/newer version, it is time to give up VB.NET and move on to C#. The earlier to do the transition, the better.
Thank you Norman Yuan for your reply
Your example works well but if you can spare some time, try placing a Parameter on your text area. For me, the error occurs when the parameter is defined
. (_reportViewer.LocalReport.SetParameters(parameters);)
Best regards....
Well, does the report design ("Report1.rdlc") have the parameter "Title" defined?
I added 2 parameters to the report design and show the values in 2 text boxes:
then I updated to code:
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MsDataReport
{
public partial class ReportDialog : Form
{
private readonly ReportViewer _reportViewer;
public ReportDialog()
{
InitializeComponent();
_reportViewer=reportViewer1 as ReportViewer;
_reportViewer.Dock = DockStyle.Fill;
}
private void ReportDialog_Load(object sender, EventArgs e)
{
_reportViewer.ProcessingMode = ProcessingMode.Local;
this.Controls.Add( _reportViewer );
using (var fs=new FileStream("Report1.rdlc", FileMode.Open))
{
_reportViewer.LocalReport.LoadReportDefinition(fs);
}
_reportViewer.LocalReport.SetParameters(
new ReportParameter("Project", "XXXXXXXXXX", true));
_reportViewer.LocalReport.SetParameters(
new ReportParameter("StartDate", DateTime.Today.ToString("yyyy-MM-dd"), true));
_reportViewer.RefreshReport();
}
}
}
Here is what the report shows in the AutoCAD plugin's dialog form:
So, I think the error you got is because the report design does not have the parameter defined as the first picture shows in my this reply.
Bonjour Norman Yuan,
Are you testing this code with Autocad 2025 (Net 8.0) or an earlier version, because I still get the same error?
Can you submit your project ?.
Bonjour Norman Yuan,
Ah, Norman, excuse me, I see from the previous post that you're using 3D Civil 2025.
Here's my project attached....
I use Autocad 2025 French, and I've tested with an English version without success.
Salutations...
Hello Norman Yuan,
I installed 3d Civil 2025 in English and tested the code successfully.
In short, it is Autocad 2025 that seems to be the problem.
Best regards...
Yes, I can verify that the reporting plugin runs OK with C3D/Map 2025, but runs into error with plain AutoCAD 2025.
Since the error reports that it has something to do with Microsoft.CodeAnalysis.VisualBasic.dll, which is included in the ReportViewerCore.WinForm Nuget package and is outputted in the AutoCAD plugin folder. So, I searched AutoCAD 2025 installation folder. I found This DLL in AutoCAD 2025's Vertical project folder (...\AutoCAD 2025\C3D[Map]), but not directly underneath the "...\AutoCAD 2025\" folder.
In the ...\AutoCAD 2025\[Vertical]\" folder, there are these 4 dlls
Miscrosoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.Scripting.dll
Microsoft.CodeAnalysis.VisualBasic.dll
Microsoft.CodeAnalysis.VisualBasic.Scripting.dll
In the ...\AutoCAD 2025\" folder, there are only 2 these files (i.e. 2 xxxx.Scripting.dll files do not exist):
Miscrosoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.VisualBasic.dll
In comparison to the plugin's output folder (i.e. the dependency DLLs from the Nuget package are also included):
Miscrosoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.VisualBasic.dll
So, I did this 2 tests:
1. copy the 2 xxxx.scripting.dll files into ...\AutoCAD 2025\ folder and run the report plugin with plain AutoCAD 2025. It works and the error is gone.
2. Copy the 2 xxxx.scripting.dll files into the plugin output folder (make sure the 2 files do not exist in the ...\AutoCAD 2025\ folder, as this is the AutoCAD 2025's original state), and run the report plugin with plain AutoCAD 2025. It also works.
So, the conclusion is that when the .NET8 runtime loads the report definition (*.rcdl file), it needs either Miscrosoft.CodeAnalysis,Scripting.dll or Microsoft.CodeAnalysis.VisualBasic.Scripting.dll, or both. However, the Nuget package somehow does not include the 2 xxxx.scripting.dll files, nor does the AutoCAD 2025 root installation folder.
I'd consider it is a bug from the NuGet package. You can simply find the 2 xxxx.scripting.dll files from "...\AutoCAD 2025\Map[Cad\ScaRuntime]" folder into the plugin's output/deployment folder.
HTH
Many thanks Norman...
I'll take the 2nd solution...
In conclusion :
I'm going to add these 3 files to my Plug-in folder
It now works perfectly well.
I attach the final version for other interested developers.
Best regards...
Can't find what you're looking for? Ask the community or share your knowledge.