powershell 5.1: new-object : Cannot find type [PoshWinRT.EventWrapper[Windows.UI.Notifications.ToastNotification,System.Object]]: verify that the assembly containing this type is loaded.
Opened this issue · 0 comments
Martinfx commented
I used this example:
$PSVersionTable.PSVersion
Major Minor Build Revision
5 1 19041 5007
new-object : Cannot find type [PoshWinRT.EventWrapper[Windows.UI.Notifications.ToastNotification,System.Object]]: verify that the assembly containing this type is loaded.
At line:26 char:14
+ ... $wrapper = new-object "PoshWinRT.EventWrapper[Windows.UI.Notificatio ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
You cannot call a method on a null-valued expression.
At line:27 char:3
+ $wrapper.Register($target, $eventName)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Register-ObjectEvent : Cannot bind argument to parameter 'InputObject' because it is null.
At line:30 char:35
+ ... -ObjectEvent -InputObject (WrapToastEvent $toast 'Activated') -EventN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Register-ObjectEvent], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.RegisterObjectEventCommand
$xml = @"
<toast>
<visual>
<binding template="ToastGeneric">
<text>Hello World</text>
<text>This is a simple toast message</text>
</binding>
</visual>
<actions>
<input id="textBox" type="text"/>
<action content="Send" activationType="system" arguments="dismiss" />
</actions>
</toast>
"@
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
$XmlDocument.loadXml($xml)
$toast = [Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime]::New($XmlDocument)
function WrapToastEvent {
param($target, $eventName)
Add-Type -Path "L:\dev\PoshWinRT.dll"
$wrapper = new-object "PoshWinRT.EventWrapper[Windows.UI.Notifications.ToastNotification,System.Object]"
$wrapper.Register($target, $eventName)
}
Register-ObjectEvent -InputObject (WrapToastEvent $toast 'Activated') -EventName FireEvent -Action {
Write-Host arguments:, $args[1].Result.arguments
Write-Host textBox:, $args[1].Result.userinput['textBox']
}
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($toast)