Writing a module for Microsoft.ReportingServices.ReportViewerControl.Winforms

Hi!

Some time ago I wrote a PS Module that generates reports based on a ReportViewer component. In that module I was using the following to load up the required assembly:
[ReflectionAssembly]::LoadWithPartialName(‘Microsoft.ReportViewer.WinForms’)

While it works fine, it depends on a ReportViewer redistributable being installed on a machine. Additionally, LoadWithPartialName method is being deprecated and I’d like to get rid of it. Basically I decided to update my PS module and wrap the latest version of ReportViewer DLLs (extracted from this package) into it (and load them up from my module folder when needed). This is where the problems begin:

  1. If I try loading the DLLs using Add-Type -Path @(<Array of paths to DLLs>) I am able to instantiate objects, etc. however in the end (when I'm calling LocalReport.Render() method I get an exception saying 'Could not load file or assembly 'Microsoft.ReportViewer.Common, Version...')
  2. If I try loading each DLL using [Reflection.Assembly]::Load([System.IO.File]::ReadAllBytes(<Path to DLL>)) I also get the exception, however this time it complains about the report definition file being invalid (which I know isn't true, since it works in identically implemented C# app, referencing those same DLLs).
From what I understand the problem in case #1 comes from the fact that somewhere underneath the Render method, an attempt is made to load those same DLLs again (supposedly to build a sandboxed AppDomain) and since the hosting application for the script is PowerShell.exe, the lookup for the DLLs is being performed within the "C:\WINDOWS\System32\WindowsPowerShell\v1.0\" folder. Is there a way to override the lookup folder for code inside these DLLs?

As for the case #2, I’m not even sure what’s wrong there.

Does anyone have any ideas on how to achieve this?

Thanks in advance!

You can try something with PowerShell classes(not sure will it help or not). Here is a good documentation on PowerShell classes.

#Example
Using NameSpace Microsoft.PowerShell.Ships

#Class definition below

[quote quote=135828]You can try something with PowerShell classes(not sure will it help or not). Here is a good documentation on PowerShell classes.

PowerShell
5 lines
<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
3
4
5
#Example
Using NameSpace Microsoft.PowerShell.Ships
#Class definition below
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] Yeah, really not sure it helps in this case but @kvprasoon, thanks for sharing the PS Classes doc, it is worth knowing...

Thanks again!