Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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. #5

Open
Martinfx opened this issue Nov 8, 2024 · 0 comments

Comments

@Martinfx
Copy link

Martinfx commented Nov 8, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant