microsoft/autogen · error · InvalidOperationException

Invalid ImageMessage, the data or url must be provided

Error message

Invalid ImageMessage, the data or url must be provided

What it means

Error "Invalid ImageMessage, the data or url must be provided" thrown in microsoft/autogen.

Source

Thrown at dotnet/src/AutoGen.Anthropic/Middleware/AnthropicMessageConnector.cs:220

        }

        return [MessageEnvelope.Create(new ChatMessage("user", content), agent.Name)];
    }

    private async Task<ImageSource> ProcessImageSourceAsync(ImageMessage imageMessage)
    {
        if (imageMessage.Data != null)
        {
            return new ImageSource
            {
                MediaType = imageMessage.Data.MediaType,
                Data = Convert.ToBase64String(imageMessage.Data.ToArray())
            };
        }

        if (imageMessage.Url is null)
        {
            throw new InvalidOperationException("Invalid ImageMessage, the data or url must be provided");
        }

        var uri = new Uri(imageMessage.Url);
        using var client = new HttpClient();
        var response = client.GetAsync(uri).Result;
        if (!response.IsSuccessStatusCode)
        {
            throw new HttpRequestException($"Failed to download the image from {uri}");
        }

        return new ImageSource
        {
            MediaType = "image/jpeg",
            Data = Convert.ToBase64String(await response.Content.ReadAsByteArrayAsync())
        };
    }

    private IEnumerable<IMessage> ProcessToolCallMessage(ToolCallMessage toolCallMessage, IAgent _)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Construct ImageMessage with either binary data or a valid URI

Example fix

new ImageMessage(role, url: uri) or supply base64 data

When it happens

Trigger: Thrown at dotnet/src/AutoGen.Anthropic/Middleware/AnthropicMessageConnector.cs:220 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/af957ee6dccbbcea. Report an issue: GitHub.