Notification Subscription API

Maksym Stepanenko asked on September 17, 2014 13:59

Hi, I'm trying to create a custom notification sender task. I've created a dummy task for testing purposes, but can't get it to work. I hope someone can guide me the right direction.

My dummy method:

public TestMethod()
        {
            var documentCategories = new DataQuery("Radware.Content.subscriptionCategories").Execute().Tables[0];
            string joinedStr = string.Join(",",string.Format("'{0}'",documentCategories.AsEnumerable().Select(r => r.Field<string>("CategoryName")).ToArray()));
            DataTable subscription = NotificationSubscriptionInfoProvider.GetSubscriptions("[SubscriptionEventSource] = 'Content' AND [SubscriptionEventData1] in ("+joinedStr+",'/%')", "[SubscriptionID]").Tables[0];           
            var list = TableToList<NotificationSubscriptionInfo>(subscription);
            CMSEmailNotificationGateway gateway = new CMSEmailNotificationGateway();
            gateway.GatewayName = "CMS.EmailGateway";
            foreach (NotificationSubscriptionInfo item in list)
            {
                gateway.NotificationSubscriptionObj = item;
                gateway.SendNotification();
            }
        }

TableToList<NotificationSubscriptionInfo>(subscription) - is a custom function that maps table to list of objects.

Works fine.

The method completes without exceptions, but in the event log I get this message :


Event ID: 154355 Event type: Error Event time: 9/17/2014 2:41:31 PM Source: CMSEmailNotificationGateway Event code: EXCEPTION User ID: 65 User name: public IP address: Description: Message: The type initializer for 'CMS.EmailEngine.EmailHelper' threw an exception.

Exception type: System.TypeInitializationException Stack Trace: at CMS.EmailEngine.EmailHelper.GetSiteId(String siteName) at CMS.EmailEngine.EmailSender.SendEmail(String siteName, EmailMessage message, Boolean sendImmediately, String setName, Int32 setRelatedId) at CMS.Notifications.CMSEmailNotificationGateway.SendNotification()

Message: Could not load file or assembly 'CMS.FileSystemStorage' or one of its dependencies. The system cannot find the file specified.

Exception type: System.IO.FileNotFoundException Stack Trace: at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString) at CMS.Base.ClassHelper.GetAssemblyInternal(String assemblyName) at CMS.IO.AbstractStorageProvider.get_ProviderAssembly() at CMS.IO.StorageProvider.CreateDirectoryProviderObject() at CMS.IO.AbstractStorageProvider.get_DirectoryProviderObject() at CMS.IO.DirectoryHelper.EnsureDiskPathInternal(String path, String startingPath) at CMS.IO.DirectoryHelper.EnsureDiskPath(String path, String startingPath) at CMS.EmailEngine.EmailHelper..cctor() Machine name: IDOG-W7 Event URL: URL referrer: User agent:


Any suggestions?

Recent Answers


Brenden Kehren answered on September 18, 2014 05:53

Check your BIN directory, looks like you are missing the CMS.FileSystemStorage dll.

0 votesVote for this answer Mark as a Correct answer

Maksym Stepanenko answered on September 18, 2014 07:48

Thanks Brenden, but I did it on the first place. The dll is there and the permissions are not read only. But I've managed to resolve the issue myself. The problem was in my visual studio permissions. When I was running the task from Visual Studio, the exception occurred, but when I published it to kentico and executed it from within the admin everything worked fine.

Can't explain this behavior, but I managed do make it work and it's enough for me.

P.S. Anyway I would like someone to explain me this weird behavior.

1 votesVote for this answer Mark as a Correct answer

Martin Danko answered on September 30, 2014 23:28

Hello Maksym,

Are you running Visual Studio as administrator? Click with right mouse button on VS and from the context menu select -> Run as admin.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.