Not all is so good in the world of using .NET from powershell code as it could be seen at first glance. I have to write poweshell code that need to use .NET library which realize text user interface. Here you can find detailed info about this library – https://www.codeproject.com/Articles/750873/Turbo-Vision-resurrected-for-Csharp-and-with-XAML
It is very nice and it realizes Turbo Vision like interface. Turbo Vision is old fashion text user interface library I am familiar with. The main code does following:
$moduleName = “$(Get-ScriptPath)\Xaml.dll”
$moduleName = “$(Get-ScriptPath)\ConsoleFramework.dll”
$moduleName = “$(Get-ScriptPath)\Binding.dll”
[ConsoleFramework.Controls.Window] $winHost =
#$window = [ConsoleFramework.Controls.Window] $consoleApplication.LoadFromXaml(“$(Get-ScriptPath)\windows-host.xml”, [object]$null)
As you see dll files is manages .NET libraries that realize all needed functionality. Unfortunately this code produces error from the title as shown below
Google shows us that this error is causes by situation when somewhere in the .NET code null reference exception occurred. Also you can see that powershell doesn’t give you any detailed info or stack trace that can be very important for debugging purpose.
My analyze gives me info that problem is related to this code of the library:
var assembly = Assembly.GetEntryAssembly();
The problem is that call to the Assembly.GetEntryAssembly() returns null if it is called from unmanaged code. This behavior is described on MSDN and also there are discussion you can find in the Internet.