High-Performance .NET Application Development & Architecture

Common .NET Errors

  • CS0019: Operator '&' cannot be applied to operands of type 'type' and 'type'

    This happens when you are trying to use the wrong operator for the specific operation.

  • CS0029: Cannot implicitly convert type 'object' to 'string'

    This error occurs when you are typically trying to present an object as a string. The solution here is to append ".ToString()," that now represents the object as a string.

  • CS0103: The name 'whatever' does not exist in the class or namespace / CS0246: The type or namespace name 'whatever' could not be found (are you missing a using directive or an assembly reference?)

    This will usually occur when you have not declared a variable globally and or it's missing altogether. CS0246 error also occurs when you are improperly declaring a object or variable, as well as it not existing in your code.

  • CS0117: 'object' does not contain a definition for 'Length'

    Again this has to do with improperly trying to convert a value. To remedy this properly cast or box the value in question.

  • CS0118: 'System.Configuration.ConfigurationSettings.AppSettings' denotes a 'property' where a 'method' was expected

    This error occurs when your AppSettings key is accessed with parentheses in VB, instead of brackets in C# or vice-versa.

  • CS0119: 'whatever' denotes a 'class' which is not valid in the given context

    One cause of this error is to improperly call an object without the "new" keyword in C# and "As New" in VB

  • Object reference not set to an instance of an object

    This runtime error is more often than not caused by your code trying to reference an object that is not available, and for the most part you've probably closed the object or set it to null or nothing somewhere in your code in all valiant attempts to clean up any unnecessary objects from memory. For example, a connection object you've opened and used, but now somewhere you've closed it and set it to nothing, and somewhere after in the code it's being called again and when it does you'll get this error. Find and delete the line and close and null your object later on. Notwithstanding, this runtime error will also occur in the circumstances shown above in CS0119.

  • CS0161: 'method name': not all code paths return a value

    This will happen when you are trying to make a function method behave like a subroutine or vice-versa. Use the proper method keyword to remedy this. Void is for methods that do not return a value, although you could response write the output. Whereas, applying a keyword value like string, int, works alongside a return value at the end of the method.

  • CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement

    This error is produced by a number of sources.

    1. If you call an object that requires parentheses () after the command, you'll get this error. Ex. database.Open() not database.Open
    2. Using an assignment operator as opposes to an equality operator
  • CS1001: Identifier expected / BC30183: Keyword is not valid as an identifier.

    Both these similar errors occur when you forget to identify a variable without a keyword, or you were inadvertently forcing a keyword to behave as a variable or type.

  • BC30451: Name 'whatever' is not declared.

    This happens when you are referencing a web form control or variable that either doesn't exist or is named different. Also by chance the control in question may be missing the mandatory runat="server" option.

  • BC30512: Option Strict On disallows implicit conversions from 'type' to 'type'.

    Improper type conversions produce this error. Convert the value or method to the proper cast to fix this.

  • BC30554/BC30560: 'object' is ambiguous.

    This error occurs when you have more than one similarly named dll in your bin folder when compiling or it matched your control inherits call. Furthermore, more than one dll root namespace or class within are named the same. Your page or control are trying to access one source file where a source file and dll may simultaneously exist.

  • BC30574: Option Strict On disallows late binding

    This can happen from any number of reasons in your code. Some common ones are:

    1. Not setting the object's proper data type
    2. An expression that binds data was incorrectly parsed against the object at runtime In Datagrids, for instance, this occurs when omitting the DataBinder.Eval method on a data field
  • BC30684: 'name' is a type and cannot be used as an expression

    This can happen usually when you forget to use the new keyword when instantiating an object or invoking a constructor.

You might also like...


About the author

Dimitrios Markatos

Dimitrios Markatos United States

Dimitrios, or Jimmy as his friends call him, is a .NET developer/architect who specializes in Microsoft Technologies for creating high-performance and scalable data-driven enterprise Web and des...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson