C# "CS0029: Cannot implicitly convert type A to B" in CI
CS0029 is an assignment-side type error: the right-hand type cannot be implicitly converted to the left-hand type. It is closely related to CS1503 (which is the argument-passing form). The fix is an explicit conversion or correcting the declared type.
What this error means
Build fails with CS0029 naming the source and target types. Reproduces deterministically for the same code.
dotnet
Mapper.cs(18,24): error CS0029: Cannot implicitly convert type 'long' to 'int'Common causes
No implicit conversion exists between the types
Assigning, for example, a long to an int or an object to a derived type requires an explicit cast the code omits.
The declared variable/return type is wrong
A method returns or a property holds a different type than the target was declared with.
How to fix it
Add an explicit conversion
- Cast or convert the value when a narrowing/explicit conversion is intended and safe.
- Use checked conversion if overflow matters.
- Rebuild.
.cs
int id = checked((int)longId);Correct the declared type
- Change the variable/property/return type to match the actual value type.
- Rebuild.
How to prevent it
- Keep declared types aligned with the values assigned to them.
- Be explicit about narrowing conversions and overflow behavior.
- Let analyzers flag risky implicit-conversion gaps.
Related guides
C# "CS1503: Argument N: cannot convert from A to B" in CIFix C# "CS1503: Argument N: cannot convert from A to B" in CI - passing an argument whose type does not match…
C# "CS0019: Operator cannot be applied to operands" in CIFix C# "CS0019: Operator X cannot be applied to operands of type A and B" in CI - combining or comparing inco…
C# "CS8602: Dereference of a possibly null reference" in CIFix C# "CS8602: Dereference of a possibly null reference" in CI - a nullable-reference warning promoted to an…