Bug 19423 - Testing if a dynamic Type variable is a string
Summary: Testing if a dynamic Type variable is a string
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-04-30 12:21 UTC by Leandro
Modified: 2014-05-02 12:02 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Leandro 2014-04-30 12:21:32 UTC
Description of Problem: 

When comparing if a dynamic Type variable is a string, it returns true even if it has a int or bool value.

Steps to reproduce the problem:

public void TestDynamic(dynamic value){
    if (value != null) {
	Console.Write (String.Concat(value.GetType().FullName,": ",value));
    if (value is int) {
	Console.WriteLine (" - I'm a int;");
    if (value is bool) {
	Console.WriteLine (" - I'm a bool;");
    if (value is string) {
        Console.WriteLine (" - I'm a string;");

TestDynamic ("a");
TestDynamic (1);
TestDynamic (true);
TestDynamic (null);

Actual Results:

System.String: a - I'm a string;
System.Int32: 1 - I'm a int;
 - I'm a string;
System.Boolean: True - I'm a bool;
 - I'm a string;

Expected Results:

System.String: a - I'm a string;
System.Int32: 1 - I'm a int;
System.Boolean: True - I'm a bool;

How often does this happen? Always

Additional Information:

Its happenning since I updated my operating system to Ubuntu 14.04 LTS with MonoDevelop 4.0.12. It doesn't happen on Ubuntu 13.10 with MonoDevelop
Comment 1 Marek Safar 2014-05-02 12:02:44 UTC
Fixed in master