Skip to content
Latchkey

C# "error CS1503: argument cannot convert from X to Y" in CI

A method call passes an argument of a type the compiler cannot convert to the parameter type. CS1503 names the argument position and both types, so the mismatch is precise.

What this error means

dotnet build fails with "error CS1503: Argument 1: cannot convert from 'string' to 'int'" at the call site, often after an API version change.

dotnet
Order.cs(18,28): error CS1503: Argument 1: cannot convert from 'string' to 'int'

Common causes

A genuine type mismatch at the call site

The caller passes the wrong type, or an overload that accepted it was removed.

A dependency version changed the signature

CI resolved a different package version whose method signature differs from the one the code was written against.

How to fix it

Pass the expected type

  1. Read the argument number and the two types in the error.
  2. Convert or supply a value of the parameter type at that call.
  3. Re-build to confirm the call type-checks.
Order.cs
// expected int, not string
Process(int.Parse(rawId));

Pin the dependency the code targets

If a package upgrade changed the signature, pin the version whose API your code uses, or update the call to the new API.

Project.csproj
<PackageReference Include="Some.Lib" Version="3.2.0" />

How to prevent it

  • Lock dependency versions so method signatures stay stable in CI.
  • Build locally against the same resolved versions CI uses.
  • Review API changes when bumping packages.

Frequently asked questions

What causes ""error CS1503: ... cannot convert from""?
The caller passes the wrong type, or an overload that accepted it was removed.
How do I fix "error CS1503: ... cannot convert from"?
Pass the expected type

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card