I have the following code in my azure webjob
class Program
{
// Please set the following connection strings in app.config for this WebJob to run:
// AzureWebJobsDashboard and AzureWebJobsStorage
static void Main()
{
try
{
Console.WriteLine(String.Format("Inicio webjob: {0}", DateTime.Now.ToString()));
JobHostConfiguration config = new JobHostConfiguration();
config.Tracing.ConsoleLevel = TraceLevel.Verbose;
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
Console.WriteLine(String.Format("Fin webjob: {0}", DateTime.Now.ToString()));
}
catch (Exception ex)
{
Console.WriteLine(String.Format("Error webjob: {0}", ex.Message));
Console.WriteLine(String.Format("Error webjob: {0}", ex.StackTrace));
//throw ex;
}
}
}
public class Functions
{
public static void CronJob([TimerTrigger("0 */1 * * * *")] TimerInfo timer)
{
try
{
Console.WriteLine(String.Format("Inicio lectura mensajes : {0}", DateTime.Now.ToString()));
string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
Configuracion.StorageAccountName, Configuracion.
StorageAccountKey);
string _guid = Guid.NewGuid().ToString();
string eventProcessorHostName = _guid;
EventProcessorHost eventProcessorHost = new EventProcessorHost(
eventProcessorHostName,
Configuracion.EventHubName,
EventHubConsumerGroup.DefaultGroupName,
Configuracion.EventHubConnectionString,
storageConnectionString);
Console.WriteLine("Registering EventProcessor...");
var options = new EventProcessorOptions();
options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options).Wait();
//Console.WriteLine("Receiving.Press enter key to stop worker.");
//Console.ReadLine();
eventProcessorHost.UnregisterEventProcessorAsync().Wait();
Console.WriteLine(String.Format("Fin lectura mensajes : {0}", DateTime.Now.ToString()));
}
catch (Exception ex)
{
throw ex;
}
}
}
However I get this error when I publish it as a webjob on the webjob console
[09/16/2016 22:59:14 > 279d7d: SYS INFO] Status changed to Initializing [09/16/2016 22:59:15 > 279d7d: SYS INFO] Run script 'SE.Medidas.Receptor.exe' with script host - 'WindowsScriptHost' [09/16/2016 22:59:15 > 279d7d: SYS INFO] Status changed to Running [09/16/2016 22:59:16 > 279d7d: ERR ] [09/16/2016 22:59:16 > 279d7d: ERR ] Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. [09/16/2016 22:59:16 > 279d7d: ERR ] at SE.Medidas.Receptor.Program.Main(String[] args) [09/16/2016 22:59:16 > 279d7d: SYS INFO] Status changed to Failed
[09/16/2016 22:59:16 > 279d7d: SYS ERR ] Job failed due to exit code -532462766
As you can see in the Console, it does not even print OUT my first Console.Writeline: "Inicio webjob: "