Could not load file or assembly 'Microsoft.ReportViewer.Common' version=15.0.0.0 from powershell script
Calling a simple rdlc report containing expression using MS Report Viewer Nuget package Microsoft.ReportingServices.ReportViewerControl.Winforms 150.900.148 from a Powershell script will throw following exception:
Échec du chargement de l'assembly hôte d'expressions. Détails: Impossible de charger le fichier ou l'assembly 'Microsoft.ReportViewer.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' ou une de ses dépendances. Le fichier spécifié est introuvable. à Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(ObjectType assemblyHolderObjectType, Exception e, ProcessingErrorCode errorCode) à Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(IExpressionHostAssemblyHolder expressionHostAssemblyHolder, Boolean includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup runtimeSetup) à Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean parametersOnly) à Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters) à Microsoft.ReportingServices.ReportProcessing.Execution.ProcessReportOdp.CreateReportInstance(OnDemandProcessingContext odpContext, OnDemandMetadata odpMetadata, ReportSnapshot reportSnapshot, Merge& odpMerge)
Code fragment:
$rv = New-Object Microsoft.Reporting.WinForms.ReportViewer
$rv.LocalReport.ReportPath = ("$BasePath\Test.rdlc")
$repDS = New-Object Microsoft.Reporting.WinForms.ReportDataSource
$repDS.Name = "DSEcheancesDues"
$repDS.Value = $dataset.Tables[0]
$rv.LocalReport.DataSources.Clear();
$rv.LocalReport.DataSources.Add($repDS);
$rv.LocalReport.Refresh();
$rv.RefreshReport();
try
{
[byte[]]$bytes = $rv.LocalReport.Render("EXCELOPENXML")
}
catch{
#$Error[0].Exception.InnerException.InnerException | out-file "error.txt"
Write-Host "Exception levéé durant render : "
$Error[0].Exception.Message
$Error[0].Exception.StackTrace
}
Whereas, running the same code from a C# test program runs fine. I run the Powershell script from the same debug folder as the C# program, and load all the present needed DLLs as the C# program. Last clue: if I remove any expression from a simple RDLC report textbox i.e: = "foo foo", the PS script runs fine.
Running Powershell from Windows 10 version 5.1.
Have any idea, I'm scratching my head on this for some days! Thank's Olivier