Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Co-variant array conversion from x to y may cause run-time exception

Rely on the correct array type to avoid runtime exceptions when adding controls to a FlowLayoutPanel.

Quick Answer: Use the non-generic version of the AddRange method, or cast the LinkLabel array to Control[] explicitly.

The warning 'Co-variant array conversion from LinkLabel[] to Control[] can cause run-time exception on write operation' is raised because you're trying to add a control (LinkLabel) to a container that only accepts controls of type Control. This can lead to unexpected behavior or errors at runtime.

🔧 Proven Troubleshooting Steps

Method 1: Specify the correct array type

  1. Step 1: Change the type of the array to match the type of controls you're adding, e.g., Control[].

Method 2: Use a cast or override the Add method

  1. Step 1: Cast each LinkLabel to Control before adding it, e.g., flPanel.Controls.AddRange(_list.Select(l => (Control)l).ToArray());.

🎯 Final Words

By following these steps, you can resolve the warning and ensure that your code runs smoothly without any runtime exceptions.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions