Azure / azure-webjobs-sdk

Azure WebJobs SDK
MIT License
739 stars 358 forks source link

Web job not starting after configuring App Insights logging #1385

Open adrashpulDA opened 7 years ago

adrashpulDA commented 7 years ago

I'm trying to configure app insights for my queue triggered web job in the way it is described here and getting the following error on web job statup:

Newtonsoft.Json.JsonException occurred HResult=0x80131500 Message=Error creating 'Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage+PersistentQueueMessageConverter'. Source=Newtonsoft.Json StackTrace: at Newtonsoft.Json.Serialization.JsonTypeReflector.<>c__DisplayClass21_0.b0(Object[] parameters) at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonConverter(Object attributeProvider) at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContractConverter(Type objectType) at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract) at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType) at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType) at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer) at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, JsonSerializerSettings settings) at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueWriter`1.d3.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.d1.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Microsoft.Azure.WebJobs.JobHost.d44.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.Azure.WebJobs.JobHost.d__25.MoveNext() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.Azure.WebJobs.JobHost.Start() at Microsoft.Azure.WebJobs.JobHost.RunAndBlock() at [My code here]

Inner Exception 1: ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

paulbatum commented 7 years ago

@brettsam Any ideas on this one?

brettsam commented 7 years ago

@adrashpulDA -- Can you share your packages.config? I wonder if you're hitting some version mismatches errors...

Kjellerup commented 7 years ago

I had this exact same problem, Turned out I was referencing Newtonsoft.Json v10.0.0.3 in a dependent project. I downgraded to Newtonsoft.Json v9.0.1 in all projects and everything started working.

mmaitre314 commented 6 years ago

I just hit the same failure after trying to enable AppInsight on my WebJob. Here is the content of packages.config (Newtonsoft.Json v10.0.3 too).

<packages>
  <package id="Microsoft.ApplicationInsights" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.4.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.4.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.4.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.4.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Http.Abstractions" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Http.Extensions" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Http.Features" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.Azure.KeyVault" version="2.3.2" targetFramework="net461" />
  <package id="Microsoft.Azure.KeyVault.Core" version="2.0.4" targetFramework="net461" />
  <package id="Microsoft.Azure.KeyVault.WebKey" version="2.0.7" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.Core" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.Extensions" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Data.Edm" version="5.8.3" targetFramework="net461" />
  <package id="Microsoft.Data.OData" version="5.8.3" targetFramework="net461" />
  <package id="Microsoft.Data.Services.Client" version="5.8.3" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.EnvironmentVariables" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.FileExtensions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.Json" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.FileProviders.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.FileProviders.Physical" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.FileSystemGlobbing" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging.Console" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Options" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Primitives" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.17.3" targetFramework="net461" />
  <package id="Microsoft.Net.Http.Headers" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.Rest.ClientRuntime" version="2.3.10" targetFramework="net461" />
  <package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.10" targetFramework="net461" />
  <package id="Microsoft.Tpl.Dataflow" version="4.5.24" targetFramework="net461" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net461" />
  <package id="ncrontab" version="3.3.0" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
  <package id="System.Buffers" version="4.4.0" targetFramework="net461" />
  <package id="System.ComponentModel.Annotations" version="4.4.0" targetFramework="net461" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net461" />
  <package id="System.Diagnostics.TraceSource" version="4.3.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.4.0" targetFramework="net461" />
  <package id="System.Spatial" version="5.8.3" targetFramework="net461" />
  <package id="System.Text.Encodings.Web" version="4.4.0" targetFramework="net461" />
  <package id="System.Threading" version="4.3.0" targetFramework="net461" />
  <package id="System.Threading.Tasks.Dataflow" version="4.8.0" targetFramework="net461" />
  <package id="System.Threading.Thread" version="4.3.0" targetFramework="net461" />
  <package id="WindowsAzure.Storage" version="8.7.0" targetFramework="net461" />
</packages>
billkiddo commented 6 years ago

Same issue, trying to use SendGrid 9.9.0 (8.0.5 doesn't work with the new APIs) which works only with Newtonsoft.Json 10.0.2 or above. Long story short the error is a show stopper in creating webjobs using latest workable SendGrid API. No answer in 3 months??? Is there a workaround?

paulbatum commented 6 years ago

No answer in 3 months???

@bilauca I have no idea why you made this comment. We responded on this issue in less than 10 days of it being opened. Please try to keep your attitude constructive.

@brettsam Since this is a webjobs specific issue, do you think a binding redirect to use Newtonsoft.Json 10.0.2 would work here?

brettsam commented 6 years ago

Some questions for @mmaitre314 / @bilauca to help narrow this down:

simmo1210 commented 6 years ago

I'm getting this error as well, here's a stack trace:

2018-01-03T21:56:40  PID[10648] Error       Unhandled Exception: Newtonsoft.Json.JsonException: Error creating 'Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage+PersistentQueueMessageConverter'. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
2018-01-03T21:56:40  PID[10648] Error          at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
2018-01-03T21:56:40  PID[10648] Error          at System.Reflection.RuntimeModule.GetTypes()
2018-01-03T21:56:40  PID[10648] Error          at System.Reflection.Assembly.GetTypes()
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.Host.Protocols.PolymorphicJsonConverter.GetTypesInHierarchy[T]() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Protocols\PolymorphicJsonConverter.cs:line 172
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.Host.Protocols.PolymorphicJsonConverter.GetTypeMapping[T]() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Protocols\PolymorphicJsonConverter.cs:line 162
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage.PersistentQueueMessageConverter..ctor() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Protocols\PersistentQueueMessage.cs:line 47
2018-01-03T21:56:40  PID[10648] Error          at CreateMicrosoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage+PersistentQueueMessageConverter()
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.JsonTypeReflector.<>c__DisplayClass21_0.<GetCreator>b__0(Object[] parameters)
2018-01-03T21:56:40  PID[10648] Error          --- End of inner exception stack trace ---
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.JsonTypeReflector.<>c__DisplayClass21_0.<GetCreator>b__0(Object[] parameters)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.JsonTypeReflector.GetJsonConverter(Object attributeProvider)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContractConverter(Type objectType)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
2018-01-03T21:56:40  PID[10648] Error          at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, JsonSerializerSettings settings)
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueWriter`1.<EnqueueAsync>d__3.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Protocols\PersistentQueueWriter.cs:line 59
2018-01-03T21:56:40  PID[10648] Error       --- End of stack trace from previous location where exception was thrown ---
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.Host.Executors.JobHostConfigurationExtensions.<CreateJobHostContextAsync>d__1.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\JobHostConfigurationExtensions.cs:line 353
2018-01-03T21:56:40  PID[10648] Error       --- End of stack trace from previous location where exception was thrown ---
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__44.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 429
2018-01-03T21:56:40  PID[10648] Error       --- End of stack trace from previous location where exception was thrown ---
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.JobHost.<StartAsyncCore>d__25.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 128
2018-01-03T21:56:40  PID[10648] Error       --- End of stack trace from previous location where exception was thrown ---
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2018-01-03T21:56:40  PID[10648] Error          at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.JobHost.Start() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 108
2018-01-03T21:56:40  PID[10648] Error          at Microsoft.Azure.WebJobs.JobHost.RunAndBlock() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 192
simmo1210 commented 6 years ago

And some config:

app.config:

<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.6.0.0" newVersion="8.6.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.7.0.0" newVersion="5.7.0.0" />
      </dependentAssembly>
    </assemblyBinding>

packages.config:

<package id="Microsoft.Azure.WebJobs" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.Core" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" version="3.0.0-beta4" targetFramework="net461" />
  <package id="Microsoft.Azure.WebJobs.ServiceBus" version="3.0.0-beta4" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
brettsam commented 6 years ago

Thanks @simmo1210 -- I'm seeing the same thing with a simple function. I'll try to figure out what's happening.

brettsam commented 6 years ago

@simmo1210 -- see #1493 for an explanation of what's happening in your case. It's related to the Azure storage library. You don't need to add Application Insights to see it; a simple WebJobs v3 app on .NET 4.6.1 would do it.

I believe your two choices are:

simmo1210 commented 6 years ago

thanks @brettsam - going back to the WebJobs v2 beta package did the trick 👍

rahulku commented 6 years ago

FYI, I ran into this just a few hours ago. I had to revert back to WebJobs v2 package. 2.1.0.

too bad, my package management is much more complicated now.

but, thank you @brettsam for having this thread!

ukphillips commented 6 years ago

I just encountered this issue using the latest WebJobs v2 with the following packages:

<packages>
  <package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net45" />
  <package id="Microsoft.Azure.WebJobs.Core" version="2.2.0" targetFramework="net46" />
  <package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net46" />
  <package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net46" />
  <package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net46" />
  <package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.29.0" targetFramework="net46" />
  <package id="Microsoft.IdentityModel.Logging" version="1.0.0" targetFramework="net46" />
  <package id="Microsoft.IdentityModel.Protocol.Extensions" version="1.0.2.206221351" targetFramework="net46" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.0.0" targetFramework="net46" />
  <package id="Microsoft.Web.WebJobs.Publish" version="1.1.0" targetFramework="net46" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3" targetFramework="net46" />
  <package id="Newtonsoft.Json" version="11.0.1" targetFramework="net46" />
  <package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net46" />
  <package id="System.Dynamic.Runtime" version="4.3.0" targetFramework="net46" />
  <package id="System.IdentityModel.Tokens.Jwt" version="4.0.2.206221351" targetFramework="net46" />
  <package id="System.Linq.Queryable" version="4.0.0" targetFramework="net46" />
  <package id="System.Net.Requests" version="4.0.11" targetFramework="net46" />
  <package id="System.Spatial" version="5.8.2" targetFramework="net46" />
  <package id="WindowsAzure.Storage" version="9.1.0" targetFramework="net46" />
</packages>
brettsam commented 6 years ago

@ukphillips -- I don't see you referencing the WebJobs host package (Microsoft.Azure.WebJobs). What error are you seeing, and what does your initialization code look like?

ukphillips commented 6 years ago

@brettsam you are correct - copying and pasting got the best of me and I had lost that from my packages. I also had another issue where the hint path in the project file was pointed at an old version of the library (1.1.2!). Once I updated the project and package.json to be inline everything worked as expected. Sorry for the false alarm!