Home Dashboard Directory Help

C# compiler: strange Compiler Error CS0266 (type1=bool?, type2=bool) by K G OConnor


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 318987
Opened: 12/20/2007 9:00:07 AM
Access Restriction: Public
User(s) can reproduce this bug


The compiler reports a Compiler Error CS0266: Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) when an explicit cast from the result of Convert.ToBoolean is casted to a bool? as a left or right hand side of a comparison, but not for assignment.
Sign in to post a comment.
Posted by Code Grail - Jason on 6/21/2011 at 7:37 PM
I get this when checking IsChecked using v4 of the .NET Framework on a checkbox in a WPF client.
Posted by Microsoft on 1/4/2008 at 1:40 PM
Dear K G OConnor,
Thanks for reporting this odd behavior. Indded it is a bug and it has been fixed in the VS2008 C# compiler as well as the .NET 3.5 framework C# compiler (csc.exe).

We will consider fixing this for a future service pack of the .NET 2.0 framework compiler and VS2005, but it is unlikely this would meet the bar.

Thanks again for the report.


Ed Maurer
Development Lead, C# compiler
Posted by Microsoft on 12/20/2007 at 5:01 PM
Thanks for your feedback. We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.
Posted by Bernard Harrison on 7/20/2011 at 3:26 PM
example code:

     //do somtihing

Cannot implicitly convert type 'bool?' to 'bool'

new code:

if((Nullable<bool>)type1 == true)
             //do somthing

Rebuild application

this worked for me