[Mono-devel-list] Warning CS0162?

Jonathan Pryor jonpryor at vt.edu
Thu May 13 07:11:33 EDT 2004


On Wed, 2004-05-12 at 21:48, Michi Henning wrote:
> Hi,
> 
> I'm getting the following when building a DLL:
> 
> 	Internal() warning CS0162: Unreachable code detected
> 
> I tried looking up CS0162 in the doc, but it doesn't appear to
> be documented. Is there any way to find out what code is considered
> unreachable and why?

Code is considered unreachable if (surprise) there's no way for the code
to be executed at runtime.  For example:

	void Cs0162 ()
	{
		Console.WriteLine ("Hello, World!");
		return;
		Console.WriteLine ("This generates CS0162");
	}

Obviously the second Console.WriteLine won't ever be executed, due to
the `return' statement on the previous line.  This is the simplest
example, but other situations can generate the warning.

> Any way to get rid of the warning?

Fix the code so that the unreachable code isn't present.

Alternatively, if you *know* that the code *is* reachable and the
warning is generated erroneously, it could be an mcs bug; please file it
in bugzilla.

 - Jon





More information about the Mono-devel-list mailing list