title: Toast Notifications in Win Forms .NET 4.5
body: <p>I've searched through a number of different posts to do with creating toast notifications from a Win Form however when these through I get an error when generating the toast notification.</p>
  
  <blockquote>
    <p>System.Exception: Element not found. (Exception from
    HRESULT:0x80070490).</p>
  </blockquote>
  
  <p>I have edited the csproj file and added the following:</p>
  
  <pre><code>  &lt;PropertyGroup&gt;
         &lt;TargetPlatformVersion&gt;10.0.10586&lt;/TargetPlatformVersion&gt;
    &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>and added the references to <code>Windows.Data</code> and <code>Windows.UI</code> and also a reference to <code>System.Runtime.dll</code> as per the suggestions in <a href="https://stackoverflow.com/questions/39139369/windows-ui-notifications-is-missing">Windows.UI.Notifications is missing</a></p>
  
  <pre><code>using Windows.Data.Xml.Dom;
  using Windows.UI.Notifications;
  using System.Windows.Forms;
  using System;
  
  namespace ToastNotify
  {
      class Notify
      {
          public void GenerateToast(string header, string content)
          {
              ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText02;
  
              XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
  
              XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
              toastTextElements[0].AppendChild(toastXml.CreateTextNode(header));
              toastTextElements[1].AppendChild(toastXml.CreateTextNode(content));
  
              XmlNodeList toastImageElements = toastXml.GetElementsByTagName("image");
              ((XmlElement)toastImageElements[0]).SetAttribute("src", "..\\..\\Resources\\icon.ico");
  
              IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
              ((XmlElement)toastNode).SetAttribute("duration", "long");
  
              ToastNotification toast = new ToastNotification(toastXml);
  
              try
              {
                  ToastNotificationManager.CreateToastNotifier().Show(toast);
              }
              catch (Exception ex)
              {
  
                  MessageBox.Show(ex.ToString());
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Any suggestions as to where I am going wrong?</p>