由于vb.net中的System.IO.FileNotFoundException,在WinForm应用程序中发送UWP Toastnotification失败

问题描述 投票:0回答:1

我正在使用vb.net(目标.Net 4.7.2)构建WinForm应用程序,并且我想从Windows UI工具包中推送ToastNotification。

我到目前为止所做的:我从NuGet安装了以下参考:

  • Microsoft.Toolkit.UWP.Notifications(6.0.0)
  • Microsoft.Toolkit.UWP.UI.Controls(6.0.0)
  • Microsoft.Windows.SDK.Contracts(10.0.18362.2005)
  • 系统运行时(4.3.1)
  • System.Runtime.InteropServices(4.3.0)
  • Microsoft.Windows.WinMD(1.0.191022.1)

我正在使用以下功能构建通知

    Private Sub CreatePush()
    Try
        Dim template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04)
        Dim textNodes = template.GetElementsByTagName("text")
        textNodes.Item(0).InnerText = title
        textNodes.Item(1).InnerText = content
        Dim imagePath As String = Application.StartupPath & "\Resources\harddrive_white.png"
        Dim imageNode = template.GetElementsByTagName("image")
        CType(imageNode.Item(0), Windows.Data.Xml.Dom.XmlElement).SetAttribute("src", imagePath)

        Dim notifier = ToastNotificationManager.CreateToastNotifier("appnamehere")
        Dim Notification = New ToastNotification(template)
        Notification.Tag = id
        AddHandler Notification.Activated, AddressOf Clicked
        AddHandler Notification.Dismissed, AddressOf Dismissed
        AddHandler Notification.Failed, AddressOf ToastFailed
        notifier.Show(Notification)
    Catch ex As Exception
        newLog("Failed showing toast notification. " & ex.Message, LogType.Exception)
        MsgBox(content, MsgBoxStyle.Information, title)
    End Try
End Sub

[运行此函数时,应用程序暂停并显示System.io.Filenotfound异常:

System.IO.FileNotFoundException:“文件或程序集” System.Runtime.InteropServices.WindowsRuntime,版本= 4.0.3.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a“或其相关性未找到。系统找不到指定的文件。“

我已经按照此处的说明表格进行操作了Windows.UI.Notifications is missing但这没有帮助。有使用Win10 ToastNotifications构建Winform应用程序的经验吗?该代码的构建没有错误,但是显示了system.runtime软件包存在版本冲突的警告(重新安装没有帮助)。

.net vb.net winforms uwp toast
1个回答
0
投票

System.IO.FileNotFoundException:“文件或程序集“ System.Runtime.InteropServices.WindowsRuntime,版本= 4.0.3.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a”或对找不到。系统找不到指定的文件。“

此错误表示它找不到System.Runtime.InteropServices.WindowsRuntime文件,通过测试,您可以添加有关此dll文件的引用。

右键单击项目>添加引用>浏览,我在C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.7.2 \ Facades路径中选择了此文件(请注意,需要根据您的实际情况找到此文件夹),然后找到System.Runtime.InteropServices.WindowsRuntime.dll并将其添加。

© www.soinside.com 2019 - 2024. All rights reserved.