-1

This is the error stated by the webjob console. Earlier the same code was running fine at least it was making a logging in application insight. This is the error:

[06/29/2022 08:14:21 > fa1ef8: SYS INFO] Status changed to Initializing
[06/29/2022 08:14:25 > fa1ef8: SYS INFO] Run script 'ArchiveOldSMBFiles.exe' with script host - 'WindowsScriptHost'
[06/29/2022 08:14:25 > fa1ef8: SYS INFO] Status changed to Running
[06/29/2022 08:14:26 > fa1ef8: ERR ] 
[06/29/2022 08:14:27 > fa1ef8: ERR ] Unhandled Exception: System.TypeInitializationException: The type initializer for 'ArchiveOldSMBFiles.Program' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized element. (D:\local\Temp\jobs\triggered\webjob7\awufcgqk.dxj\Debug\ArchiveOldSMBFiles.exe.config line 38)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    --- End of inner exception stack trace ---
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.ConfigurationManager.GetSection(String sectionName)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Net.Configuration.SettingsSectionInternal.get_Section()
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Net.Sockets.Socket.InitializeSockets()
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at System.Net.NetworkInformation.NetworkChange.AddressChangeListener.StartHelper(NetworkAddressChangedEventHandler caller, Boolean captureContext, StartIPOptions startIPOptions)
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.Network.AddAddressChangedEventHandler(NetworkAddressChangedEventHandler handler) in /_/BASE/src/ServerTelemetryChannel/Implementation/Network.cs:line 12
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.TransmissionPolicy.NetworkAvailabilityTransmissionPolicy.SubscribeToNetworkAddressChangedEvents() in /_/BASE/src/ServerTelemetryChannel/Implementation/TransmissionPolicy/NetworkAvailabilityTransmissionPolicy.cs:line 36
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.TransmissionPolicy.NetworkAvailabilityTransmissionPolicy.Initialize(Transmitter transmitter) in /_/BASE/src/ServerTelemetryChannel/Implementation/TransmissionPolicy/NetworkAvailabilityTransmissionPolicy.cs:line 19
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.TransmissionPolicy.TransmissionPolicyCollection.Initialize(Transmitter transmitter) in /_/BASE/src/ServerTelemetryChannel/Implementation/TransmissionPolicy/TransmissionPolicyCollection.cs:line 49
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation.Transmitter..ctor(TransmissionSender sender, TransmissionBuffer transmissionBuffer, TransmissionStorage storage, TransmissionPolicyCollection policies, BackoffLogicManager backoffLogicManager) in /_/BASE/src/ServerTelemetryChannel/Implementation/Transmitter.cs:line 57
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel..ctor(INetwork network, IApplicationLifecycle applicationLifecycle) in /_/BASE/src/ServerTelemetryChannel/ServerTelemetryChannel.cs:line 52
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel..ctor() in /_/BASE/src/ServerTelemetryChannel/ServerTelemetryChannel.cs:line 41
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at ArchiveOldSMBFiles.Program..cctor() in D:\Projects\ArchiveOldSMBFiles\Program.cs:line 30
[06/29/2022 08:14:27 > fa1ef8: ERR ]    --- End of inner exception stack trace ---
[06/29/2022 08:14:27 > fa1ef8: ERR ]    at ArchiveOldSMBFiles.Program.Main(String[] args)
[06/29/2022 08:14:27 > fa1ef8: SYS INFO] Status changed to Failed
[06/29/2022 08:14:27 > fa1ef8: SYS ERR ] Job failed due to exit code -532462766

My code:

class Program
    {
        static IServiceCollection services = new ServiceCollection()
        .AddLogging(loggingBuilder => loggingBuilder.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Trace))
        .AddSingleton(typeof(ITelemetryChannel), new ServerTelemetryChannel())
        .AddApplicationInsightsTelemetryWorkerService(ConfigurationManager.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"]);

        static IServiceProvider serviceProvider = services.BuildServiceProvider();
        static ILogger<Program> logger = serviceProvider.GetRequiredService<ILogger<Program>>();
        static TelemetryClient telemetryClient = serviceProvider.GetRequiredService<TelemetryClient>();

        public static void Main(string[] args)
        {
            try
            {
                var _storageConn = ConfigurationManager
                .AppSettings["PaperCaptureStorageConnectionString"];
                ServicePointManager.DefaultConnectionLimit = 50;
               
                JobHostConfiguration config = new JobHostConfiguration();
                config.StorageConnectionString = _storageConn;
              
                var host = new JobHost(config);
                Task callTask = host.CallAsync(typeof(Program).GetMethod(nameof(Program.ProcessMethod)));

                callTask.Wait();
                host.RunAndBlock();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        [NoAutomaticTrigger]
        public static void ProcessMethod()
        {
            using (telemetryClient.StartOperation<RequestTelemetry>("ArchiveOldSMBFiles1233"))
            {
                logger.LogInformation("-ArchiveOldSMBFiles.Main Execution Started");
                var totalDeletedFiles = 0;
                try
                {
                    string jsonTemplate = string.Empty;
                    string fileShareName = string.Empty;
                    Console.WriteLine("Before unity of work");
                    using (var unitOfWork = new DataConnector().UnitOfWork)
                    {
                        Console.WriteLine("After unity of work");
                        jsonTemplate = ConfigurationService.GetConfigValueByConfigCode(
                            BusinessLogic.Helper.Constants.ConfigType.AzureConstantValues
                            , BusinessLogic.Helper.Constants.ConfigCode.SMBRemoveOldFile, unitOfWork);

                        Console.WriteLine("This is your json: " + jsonTemplate);                       
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("After Catch");
                    Console.WriteLine("Crash: "+ ex.ToString());
                    logger.LogError(ex.ToString());
                }
                finally
                {
                    Console.WriteLine("After finally");
                    telemetryClient.Flush();
                }
            }
        }
}

I have fixed the Azure SQL connection issue which was caused by the wrong Azure connection string. I am uploading my webjob by zipping Debug folder and uploading it.

Psychonaut007
  • 167
  • 3
  • 13

1 Answers1

1

To resolve the error Job failed due to exit code -532462766, please check the following:

  • This error usually occurs when the config file is broken.
  • After installing the Application Insights try comparing the configuration files.
  • Please check whether you have web.config file. If not, try creating web.config in console app similar to app.config and republish SO Thread by Lucas Huet-Hudson.
  • Try copying the the programname.exe.config file along with the exe as answered by Nasir Razzaq in the above thread.
  • Try to disable the dashboard logging as suggested by NicolajHedeager in this GitHub Blog.

If the issue still persists, raise Azure Support Ticket to know the root cause of the issue.

For more in detail, please refer below links:

Turning a console app into a long-running Azure WebJob – Sander van de Velde (wordpress.com) by Sander van de Velde

Azure WebJob fails with exit code 532462766 (microsoft.com) by Anastasia Black

Sridevi
  • 10,599
  • 1
  • 4
  • 17