0

Here is the main procedure for scheduling an output task

Public Sub ScheduleOutput()

    Dim sf As ISchedulerFactory = New StdSchedulerFactory()

    Dim scheduler As IScheduler = sf.GetScheduler()
        scheduler.Start()

    Dim job As IJobDetail = JobBuilder.Create(Of OutputJob)().
                WithIdentity("output", "output").Build()

    Dim trigger As ITrigger = TriggerBuilder.Create().
                WithIdentity("trigger", "trigger").ForJob("output").
                WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(setHour.Text, setMinute.Text)).
                Build()
    MsgBox("end")

End Sub

and the job class

Public Class OutputJob
    Implements IJob

    Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute

        Output()

    End Sub

    Public Sub Output()

        Dim b = Convert.FromBase64String(HttpContext.Current.Request.Form("encodedhtml"))
        Dim html = System.Text.Encoding.UTF8.GetString(b)
        
        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.ContentType = "text/html"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=""Dashboard.html""")
        HttpContext.Current.Response.Write(html)
        HttpContext.Current.Response.End()

    End Sub

End Class

Web.config file

<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
        <arg key="configType" value="INLINE"/>
        <arg key="configFile" value="~/log4net.config"/>
        <arg key="level" value="INFO" />
      </factoryAdapter>
    </logging>
  </common>
  <log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d [%t] %-5p %l - %m%n" />
      </layout>
    </appender>
    <root>
      <level value="INFO" />
      <appender-ref ref="EventLogAppender" />
    </root>
  </log4net>
</configuration>

When I try to run the code, an exception occurred in Dim sf As ISchedulerFactory = New StdSchedulerFactory()

An exception of type 'System.TypeInitializationException' occurred in something.dll but was not handled in user code

Additional information: The type initializer for 'Quartz.Impl.StdSchedulerFactory' threw an exception.

Exception messages in the Output (shown at the bottom of Visual Studio):

A first chance exception of type 'Common.Logging.ConfigurationException' occurred in Common.Logging.dll A first chance exception of type 'System.TypeInitializationException' occurred in something.dll

How can I fix the exception?

And any other parts in the code that can cause errors/exceptions?

I have struggled for long about this and have searched for a lot of solutions, but none of them can actually help me (or just I don't know how to modify in order to fit my code) because I really lack knowledge about task scheduling and configuration settings.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ursidae
  • 87
  • 9

1 Answers1

1

Quartz depends only on a single third-party library called Common.Logging (which contains logging abstractions that allow you to use the logging provider that suites you the best). You need to have Quartz.dll, Commong.Logging.dll and Commong.Logging.Core.dll beside your app binaries to successfully run Quartz.NET

And replace Common.Logging.Log4Net1213.dll section with:

  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
        <arg key="configType" value="INLINE"/>
        <arg key="level" value="INFO" />
      </factoryAdapter>
    </logging>
  </common>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.3.1.0" newVersion="3.3.1.0" />
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
Danut Radoaica
  • 1,860
  • 13
  • 17
  • which file it is looking for? – Danut Radoaica May 27 '19 at 08:16
  • you should keep the and sections and replace only the one; this will configure Common.Logging with the log4net config from the web.config file – Danut Radoaica May 27 '19 at 08:18
  • I've just done what you suggested, but then System.IO.FileLoadException occurred. "Could not load file or assembly 'Common.Logging.Core' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)" – Ursidae May 27 '19 at 08:35
  • I have never removed the and sections – Ursidae May 27 '19 at 08:38
  • in the build result you should have the following files: Quartz.dll, Commong.Logging.dll , Commong.Logging.Core.dll and Common.Logging.Log4Net1213.dll, if not, you should add them as direct references in your project – Danut Radoaica May 27 '19 at 08:50
  • another possibility is that you update the references to unsupported versions, for example Quartz -Version 2.6.2 needs Common.Logging -Version 3.3.1 and Common.Logging.Core -Version 3.3.1 – Danut Radoaica May 27 '19 at 08:58
  • Added but exception still occurs. The version matches each other too (just exactly the same as the example you mentioned) as all of them are from the same directory. – Ursidae May 27 '19 at 09:02
  • 1
    try to add the following in the web.config file: – Danut Radoaica May 27 '19 at 09:21
  • It works now! Actually I had added something similar before your above comment, but the version number in `` was wrong, so it works when I changed to your above code. Thanks for your help! – Ursidae May 27 '19 at 10:14