Forum Discussion
Agents SDK Teams Bot crashes MSFT.Agents.Core.ProtocolJsonSerializer..cctor() with CLR (0x80131506)
@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
- 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.
- 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.
- 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.
- 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:
- Azure Functions DI guidance (avoid resolving heavy services during startup): https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#regis…
- Isolated worker guidance for startup and configuration: https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#start-up-and-…
- DI best practices (avoid heavy work/async in constructors, keep factories fast): https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#recommenda…
- .NET dependency loading and assembly resolution reference (for version conflict investigation): https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/overview
Thanks,
Nivedipa
---------------------------------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Solution**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.