locked
The notification could not be formatted. RRS feed

  • Question

  • I've developed a custom formatter component to transform complex XML documents, and get the following error when trying to use it:

    <NotificationServicesEvent>
     <Description>
      The notification could not be formatted.
     </Description>
     <Context>
    <EventParameters>
     <InstanceName>NHSDInstance</InstanceName>
     <ApplicationName>NHSD</ApplicationName>
     <Distributor Id>1</Distributor Id>
     <Distributor Name>NHSDDist1</Distributor Name>
     <Distributor Work Item Id>4</Distributor Work Item Id>
     <NotificationClassName>NHSDValidationNotifications</NotificationClassName>
     <Notification Id>7</Notification Id>
    </EventParameters>
     </Context>
     <Description>
      Request for the permission of type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
     </Description>
     <Instance>NHSDInstance</Instance>
     <ApplicationName>NHSD</ApplicationName>
     <Component>Distributor</Component>
     <ComponentDetails>
    DistributorName: NHSDDist1
     </ComponentDetails>
     <Thread>284</Thread>
    </NotificationServicesEvent>

    After extensive googling, I'm still pretty much none the wiser.

    The dll was created using v1.0.3705, which, I'm guessing is at the root of the problem.

    I've also included the dll code, as I think this possibly has a bearing too.

    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Globalization;
    using System.IO;
    using System.Net;
    using System.Text;
    using System.Xml;
    using System.Xml.Xsl;
    using System.Xml.XPath;
    using Microsoft.SqlServer.NotificationServices;
    using Microsoft.SqlServer.NotificationServices.Common;

    namespace ContentFormatter
    {
     public class ComplexTransformation : IContentFormatter
     {
      private bool initialised;

      private string xsltBaseDirectoryPath;
      private string xsltFileName;

      private string xmlBaseDirectoryPath;
      private string xmlFileName;

      private bool digest;
      private bool disableEscaping;
      
      private NSOtherLogger logger;

      public ComplexTransformation()
      {}

      public ComplexTransformation(string instanceName)
      {
       this.xsltBaseDirectoryPath = null;
       this.xsltFileName = null;

       this.xmlBaseDirectoryPath = null;
       this.xmlFileName = null;
       
       this.initialised = false;
       this.disableEscaping = false;

       string logText = NSStringResource.GetLocaleString(NSLocaleStringEnum.XsltFormatterComponentName);
       this.logger = new NSOtherLogger(instanceName, logText);

      } 

      public void Initialize(StringDictionary arguments, bool digest)
      {
       if (!this.initialised)
       {    
        if (!arguments.ContainsKey("XsltFileName"))
        {
         throw new NSException(NSEventEnum.XsltFileNameTagMissing);
        }
        
        if (!arguments.ContainsKey("XsltBaseDirectoryPath"))
        {
         throw new NSException(NSEventEnum.XsltBaseDirectoryPathTagMissing);
        }

        if (!arguments.ContainsKey("XmlFileName"))
        {
         throw new NSException("Input XML path tag missing");
        }
        
        if (!arguments.ContainsKey("XmlBaseDirectoryPath"))
        {
         throw new NSException("Input XML base directory path tag missing");
        }

        this.xsltBaseDirectoryPath = arguments["XsltBaseDirectoryPath"];
        this.xsltFileName = arguments["XsltFileName"];
        this.xmlBaseDirectoryPath = arguments["XmlBaseDirectoryPath"];
        this.xmlFileName = arguments["XmlFileName"];

        if (arguments.ContainsKey("DisableEscaping"))
        {
         try
         {
          this.disableEscaping = bool.Parse(arguments["DisableEscaping"]);
         }
         catch (Exception exception1)
         {
          NSEventParameters parameters1 = new NSEventParameters();
          parameters1.AddParameter(NSEventParamEnum.XsltDisableEscapingValue, arguments["DisableEscaping"]);
          throw new NSException(NSEventEnum.XsltDisableEscapingValueInvalid, parameters1, exception1);
         }
        }
        this.digest = digest;
        this.initialised = true;
       }
      }


      public string FormatContent(string subscriberLocale, string deviceTypeName, RecipientInfo recipientInfo, Hashtable[] rawContent)
      {
       string XmlLocation = this.xmlBaseDirectoryPath + this.xmlFileName;
       string XsltLocation = this.xsltBaseDirectoryPath + this.xsltFileName;
       RenderVariables(XmlLocation);
       string outputXHTML = null;
       
       try
       {
        outputXHTML = this.Transform(XmlLocation,XsltLocation);
       }
       catch (Exception FormatException)
       {
        NSException ThrownException = FormatException as NSException;
        if (ThrownException == null)
        {
         ThrownException = new NSException(NSEventEnum.XsltFormatterUnknownError, FormatException);
        }
        this.logger.LogError(ThrownException);
        throw ThrownException;
       }
       return outputXHTML;
      }

      private void RenderVariables(string Variable)
      {
       // create a writer and open the file
       TextWriter tw = new StreamWriter(@"C:\Dump.txt");

       // write a line of text to the file
       tw.WriteLine(Variable);

       // close the stream
       tw.Close();
      }


      public void Close()
      {
      }

      public string Transform(string XmlPath, string XslPath)
      {       
       string NullString = null;

       XPathDocument XPathDocument;   
       XslTransform XslTrans;
          
       // Create the output stream
       StringBuilder DocStringBuilder;
       TextWriter DocTextWriter = null;   
       
       try
       {  
        // Read XML
        XPathDocument = new XPathDocument(XmlPath);
       
        // Create a new XslTransform object.
        XslTrans = new XslTransform();
        // Load the stylesheet.
        XslTrans.Load(XslPath);
       
        // Create the output stream
        DocStringBuilder = new StringBuilder();
        DocTextWriter = new StringWriter(DocStringBuilder);
        
        XslTrans.Transform(XPathDocument,null,DocTextWriter);   

       }
       catch (XsltException TransformException)
       {
        NSEventParameters EventParameters = new NSEventParameters();
        EventParameters.AddParameter(NSEventParamEnum.XsltTransformFile, NullString);
        throw new NSException(NSEventEnum.XsltInvalidTransform, EventParameters, TransformException);
       }
       finally
       {
        DocTextWriter.Close();
       }

       // Push result
       return DocStringBuilder.ToString();       
      }  

     }
    }

    Any idea on a resolution?

    Joe

    Tuesday, September 27, 2005 11:03 AM