Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Resolve errors and warnings for
This article covers the following compiler errors and warnings:
- CS0144: Cannot create an instance of the abstract type or interface 'type'
- CS0712: Cannot create an instance of the static class 'type'
- CS1526: A new expression requires an argument list or (), [], or {} after type
- CS8181: 'new' cannot be used with tuple type. Use a tuple literal expression instead.
- CS8386: Invalid object creation
- CS8752: The type 'type' may not be used as the target type of new()
- CS8753: Use of new() is not valid in this context
- CS8754: There is no target type for 'expression'
Types that can't be instantiated
- CS0144: Cannot create an instance of the abstract type or interface 'type'
- CS0712: Cannot create an instance of the static class 'type'
The new operator can only create instances of concrete, non-static types. The language prohibits instantiating abstract classes, interfaces, and static classes because these types are incomplete or aren't designed to have instances.
- Create a concrete class that derives from the abstract class, or create a class that implements the interface, then instantiate that concrete type (CS0144). You can't use
newdirectly on anabstractclass or aninterfacebecause they don't provide complete implementations. If you own the type, you can also remove theabstractmodifier to make the class directly instantiable. - Remove the
newexpression and access the static class members directly through the class name (CS0712). Static classes exist solely to group static members and can't be instantiated. If you need an instance, remove thestaticmodifier from the class declaration.
For more information, see abstract, interface, and Static Classes and Static Class Members.
new expression syntax errors
- CS1526: A new expression requires an argument list or (), [], or {} after type
- CS8181: 'new' cannot be used with tuple type. Use a tuple literal expression instead.
- CS8386: Invalid object creation
These errors occur when the syntax of a new expression is malformed or when you use new with a type that requires a different creation syntax.
- Add an argument list
(), array dimensions[], or an initializer{}after the type name in anewexpression (CS1526). Thenewoperator requires one of these to indicate how the object is constructed. For example, writenew MyClass()instead ofnew MyClass. - Replace
new (int, string)(...)with a tuple literal expression like(1, "hello")(CS8181). Tuple types use a dedicated literal syntax rather than thenewoperator. To create a tuple, use parenthesized values directly:(int X, string Y) point = (1, "hello");. - Ensure the
newexpression targets a valid constructible type (CS8386). This error occurs when the compiler can't determine a valid object creation from the syntax. Verify you're using a type name that supports construction, and that the expression is syntactically complete.
For more information, see new operator and Tuple types.
Target-typed new expressions
- CS8752: The type 'type' may not be used as the target type of new()
- CS8753: Use of new() is not valid in this context
- CS8754: There is no target type for 'expression'
Target-typed new expressions (introduced in C# 9) let you omit the type name when the compiler can infer it from context, as in MyClass x = new();. These errors occur when the compiler can't determine a valid target type or when the inferred type isn't constructible.
- Use an explicit type name instead of target-typed
new()when the target type is an interface, abstract class, static class, or other non-constructible type (CS8752). Target-typednew()infers the type from the left-hand side, but the inferred type must be a concrete, instantiable type. Write the fullnew ConcreteType()instead. - Move the
new()expression to a context where a target type is available (CS8753). Target-typednewis valid only in contexts where the compiler can determine a type, such as variable declarations with an explicit type, assignment expressions, return statements with a known return type, or argument positions with a known parameter type. You can't usenew()in contexts likevar x = new();where no target type exists. - Provide an explicit type for the
newexpression when no target type can be inferred (CS8754). This error occurs when you usenew()in a position where the compiler has no way to determine what type to construct. Replacenew()withnew ExplicitType(), or declare the variable with an explicit type rather thanvar.
For more information, see Target-typed new expressions.