Forum Discussion

LHowlin_'s avatar
LHowlin_
Copper Contributor
Aug 22, 2025

Agents SDK Teams Bot crashes MSFT.Agents.Core.ProtocolJsonSerializer..cctor() with CLR (0x80131506)

 

Teams Bot running off Azure Functions .NET 8 (isolated) crashes at Microsoft.Agents.Core.Serialization.ProtocolJsonSerializer..cctor() with Fatal error. Internal CLR error (0x80131506) when initializing Microsoft.Agents.Storage.Blobs

Hi team — I’m setting up context storage for a Teams bot using the Microsoft Agents SDK. When the message handler function executes, testing via adding the bot to a meeting chat, DI constructs BlobsStorage, the Functions worker process crashes with a fatal CLR error originating from the Agents serialization bootstrap.


My issue seems related to these two issues: 

https://github.com/microsoft/Agents/issues/224

 

https://github.com/microsoft/Agents-for-net/issues/386

I have tried the recommended fix of pinning my installed packages to version 1.1.151, and I still encounter this error.

 

csproj:

<PackageReference Include="AdaptiveCards.Templating" Version="2.0.5" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.2.0-beta.5" />
<PackageReference Include="Azure.Data.Tables" Version="12.11.0" />
<PackageReference Include="Microsoft.Agents.Builder.Dialogs" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Core" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Storage.Blobs" Version="1.1.151" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.5" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.2" />
<PackageReference Include="Microsoft.Agents.Authentication.Msal" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Hosting.AspNetCore" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Client" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Connector" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Storage" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Storage.Transcript" Version="1.1.151" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.23.0" />
<PackageReference Include="Microsoft.Graph" Version="5.91.0" />
<PackageReference Include="Microsoft.Agents.Builder" Version="1.1.151" />
<PackageReference Include="Microsoft.Agents.Extensions.Teams" Version="1.1.151" />
 
  <!-- Exclude TeamsFx wwwroot static files which are for frontend only. -->
      
  <!-- Fix system package downgrade -->
 <PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="All" />
 <PackageReference Include="Microsoft.TeamsFx" Version="3.0.0" />
 <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
 
 
My full stack trace is below:

 

     Microsoft.Agents.Core.dll!Microsoft.Agents.Core.Serialization.SerializationInitAttribute.InitSerialization()    Unknown
     Microsoft.Agents.Core.dll!Microsoft.Agents.Core.Serialization.ProtocolJsonSerializer.ProtocolJsonSerializer()    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     Microsoft.Agents.Core.dll!Microsoft.Agents.Core.Serialization.ProtocolJsonSerializer.SerializationOptions.get()    Unknown
     Microsoft.Agents.Storage.Blobs.dll!Microsoft.Agents.Storage.Blobs.BlobsStorage.BlobsStorage()    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     Microsoft.Agents.Storage.Blobs.dll!Microsoft.Agents.Storage.Blobs.BlobsStorage.BlobsStorage(System.Uri blobContainerUri, Azure.Core.TokenCredential tokenCredential, Azure.Storage.StorageTransferOptions storageTransferOptions, Azure.Storage.Blobs.BlobClientOptions options, System.Text.Json.JsonSerializerOptions jsonSerializerOptions)    Unknown
>    MrMinute.dll!Program.<Main>$.AnonymousMethod__0_1(System.IServiceProvider sp) Line 47    C#
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryCallSite factoryCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSiteMain(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSiteMain(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSiteMain(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite transientCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, object>.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext argument)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.RealizeService.AnonymousMethod__0(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceIdentifier serviceIdentifier, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope)    Unknown
     Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(System.Type serviceType)    Unknown
     Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorInfoEx.GetService(System.IServiceProvider serviceProvider, int parameterIndex)    Unknown
     Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(System.IServiceProvider provider)    Unknown
     Microsoft.Extensions.DependencyInjection.Abstractions.dll!Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(System.IServiceProvider provider, System.Type instanceType, object[] parameters)    Unknown
     Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Azure.Functions.Worker.DefaultFunctionActivator.CreateInstance(System.Type instanceType, Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     MrMinute.dll!TeamsToDynamics.DirectFunctionExecutor.ExecuteAsync(Microsoft.Azure.Functions.Worker.FunctionContext context) Line 104    C#
     Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Azure.Functions.Worker.Pipeline.FunctionExecutionMiddleware.Invoke(Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Extensions.Hosting.MiddlewareWorkerApplicationBuilderExtensions.UseFunctionExecutionMiddleware.AnonymousMethod__1_2(Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(Microsoft.Azure.Functions.Worker.FunctionContext context, Microsoft.Azure.Functions.Worker.Middleware.FunctionExecutionDelegate next)    Unknown
     Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Extensions.Hosting.MiddlewareWorkerApplicationBuilderExtensions.UseOutputBindingsMiddleware.AnonymousMethod__3(Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(Microsoft.Azure.Functions.Worker.FunctionContext context, Microsoft.Azure.Functions.Worker.Middleware.FunctionExecutionDelegate next)    Unknown
     [Resuming Async Method]    
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.<Invoke>d__5>.ExecutionContextCallback(object s)    Unknown
     System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.<Invoke>d__5>.MoveNext(System.Threading.Thread threadPoolThread)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.<Invoke>d__5>.MoveNext()    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.AspNetCore.Http.HttpContext>.SetResult(Microsoft.AspNetCore.Http.HttpContext result)    Unknown
     [Completed] Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.SetFunctionContextAsync(string invocationId, Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.<SetFunctionContextAsync>d__7>.ExecutionContextCallback(object s)    Unknown
     System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<Microsoft.AspNetCore.Http.HttpContext>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.<SetFunctionContextAsync>d__7>.MoveNext(System.Threading.Thread threadPoolThread)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.__Canon>.AsyncStateMachineBox<Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.<SetFunctionContextAsync>d__7>.MoveNext()    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.OutputWaitEtwEvents.AnonymousMethod__12_0(System.Action innerContinuation, System.Threading.Tasks.Task innerTask)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(System.Action action, bool allowInlining)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task.CancellationPromise<bool>.System.Threading.Tasks.ITaskCompletionAction.Invoke(System.Threading.Tasks.Task completingTask)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task.RunContinuations(object continuationObject)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.Task<bool>.TrySetResult(bool result)    Unknown
     System.Private.CoreLib.dll!System.Threading.Tasks.TaskCompletionSource<bool>.SetResult(bool result)    Unknown
     Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.ContextReference.InvokeFunctionAsync()    Unknown
     Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.DefaultHttpCoordinator.RunFunctionInvocationAsync(string invocationId)    Unknown
     Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.AspNetCore.Http.FunctionsHttpContextExtensions.InvokeFunctionAsync(Microsoft.AspNetCore.Http.HttpContext context)    Unknown
     Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.dll!Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.WorkerRequestServicesMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)    Unknown
     Microsoft.AspNetCore.HostFiltering.dll!Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(Microsoft.AspNetCore.Http.HttpContext context)    Unknown
     Microsoft.AspNetCore.Server.Kestrel.Core.dll!Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests<Microsoft.AspNetCore.Hosting.HostingApplication.Context>(Microsoft.AspNetCore.Hosting.Server.IHttpApplication<Microsoft.AspNetCore.Hosting.HostingApplication.Context> application)    Unknown
     [Resuming Async Method]    
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238<Microsoft.AspNetCore.Hosting.HostingApplication.Context>>.ExecutionContextCallback(object s)    Unknown
     System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238<Microsoft.AspNetCore.Hosting.HostingApplication.Context>>.MoveNext(System.Threading.Thread threadPoolThread)    Unknown
     System.Private.CoreLib.dll!System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<ProcessRequests>d__238<System.__Canon>>.ExecuteFromThreadPool(System.Threading.Thread threadPoolThread)    Unknown
     System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()    Unknown
     System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()    Unknown
     [Async Call Stack]    
     [Async] Microsoft.Azure.Functions.Worker.Core.dll!Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(Microsoft.Azure.Functions.Worker.FunctionContext context)    Unknown
     [Async] Microsoft.Azure.Functions.Worker.Grpc.dll!Microsoft.Azure.Functions.Worker.Handlers.InvocationHandler.InvokeAsync(Microsoft.Azure.Functions.Worker.Grpc.Messages.InvocationRequest request)    Unknown
     [Async] Microsoft.Azure.Functions.Worker.Grpc.dll!Microsoft.Azure.Functions.Worker.GrpcWorker.ProcessRequestCoreAsync(Microsoft.Azure.Functions.Worker.Grpc.Messages.StreamingMessage request)    Unknown
     [Async] System.Private.CoreLib.dll!System.Threading.Tasks.Task.Run    Unknown
 
 
 
 
Thank you in advance for the assistance
 
 
 

1 Reply

  • @LHowlin - Thanks for bringing this issue to our attention.

    The crash occurs when the Agents SDK static initializer runs as DI constructs BlobsStorage within the Functions worker. This static initialization can trigger runtime or assembly behaviors—such as JSON/serializer/converter registration or reflection—that conflict with the Functions host or your dependency graph, resulting in the fatal CLR error you shared.

    Immediate, high-value actions

    1. Prevent early static initialization
      • Avoid instantiating Microsoft.Agents.Storage.Blobs.BlobsStorage during host startup or registration. Instead, register a factory or Lazy provider and create the instance only when first needed during function execution. This prevents the Agents SDK static constructor from running at DI build time.
      • Recommended approach: register a factory or lazy provider in Program.cs, then invoke the factory inside the function handler to keep DI registration lightweight.
    2. Identify or confirm a compatibility issue
      • Test outside Functions: build a small console app referencing the same Agents packages and instantiate BlobsStorage to check for the same crash. If it fails, it's likely a library/runtime incompatibility; if not, the issue relates to Azure Functions startup.
      • Review transitive package versions for conflicts (e.g., System.Text.Json, runtime-targeting packages, Microsoft.NETCore.Targets). The Microsoft.NETCore.Targets package may be causing resolution issues.
    3. If lazy initialization resolves the crash
      • Continue using the lazy-factory approach in production, as it is a reliable workaround until a library fix is released.
    4. If lazy initialization does not resolve the crash
      • Gather runtime details to report a precise bug: include output from dotnet --info, a list of all resolved (transitive) packages, Functions host version, function app settings, exact package versions, and a memory dump or full stack trace. Attach a minimal repro that demonstrates the crash.

    Ref Docs:

Resources