# ArgumentException: Buffer 'MyBuffer' has been declared as a structured buffer in the shader, but the C# script is binding a different type (ComputeBuffer or GraphicsBuffer)

- **ID:** `unity/graphics-buffer-mismatch`
- **Domain:** unity
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

Mismatch between the buffer type declared in the HLSL shader (e.g., StructuredBuffer) and the buffer type created in C# (e.g., ComputeBuffer with wrong stride or GraphicsBuffer with wrong target).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Unity 2022.3 | active | — | — |
| Unity 2023.1 | active | — | — |
| Unity 6.0 | active | — | — |

## Workarounds

1. **Ensure the C# ComputeBuffer stride equals the size of the struct used in the shader. For a float3 buffer, stride = 12 bytes. Example: ComputeBuffer buffer = new ComputeBuffer(count, sizeof(float) * 3); shader.SetBuffer(kernel, "MyBuffer", buffer);** (90% success)
   ```
   Ensure the C# ComputeBuffer stride equals the size of the struct used in the shader. For a float3 buffer, stride = 12 bytes. Example: ComputeBuffer buffer = new ComputeBuffer(count, sizeof(float) * 3); shader.SetBuffer(kernel, "MyBuffer", buffer);
   ```
2. **If using GraphicsBuffer, set the correct target (e.g., GraphicsBuffer.Target.Structured). Example: GraphicsBuffer gfxBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, stride);** (85% success)
   ```
   If using GraphicsBuffer, set the correct target (e.g., GraphicsBuffer.Target.Structured). Example: GraphicsBuffer gfxBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, count, stride);
   ```

## Dead Ends

- **** — Increasing the buffer size does not fix type mismatch; the issue is stride or target, not capacity. (60% fail)
- **** — Switching to a different shader variant does not change the buffer declaration mismatch. (30% fail)
