Home Dashboard Directory Help
Search

C# ‘is’ type check on struct - odd .NET 4.0 x86 optimization behavior by Jacob Stanley1


Status: 

Closed
 as Fixed Help for as Fixed


15
0
Sign in
to vote
Type: Bug
ID: 558649
Opened: 5/12/2010 8:24:05 AM
Access Restriction: Public
0
Workaround(s)
view
7
User(s) can reproduce this bug

Description

Bug report for: http://stackoverflow.com/questions/2819102/c-is-type-check-on-struct-odd-net-4-0-x86-optimization-behavior

Since upgrading to VS2010 I'm getting some very strange behavior with the 'is' keyword.

The program below (test.cs) outputs True when compiled in debug mode (for x86) and False when compiled with optimizations on (for x86). Compiling all combinations in x64 or AnyCPU gives the expected result, True.

All combinations of compiling under .NET 3.5 give the expected result, True.

I'm using the batch file below (runtest.bat) to compile and test the code using various combinations of compiler .NET framework.
Details
Sign in to post a comment.
Posted by Microsoft on 8/18/2010 at 5:25 PM
This bug will be fixed in a future version of the runtime. I'm afraid it's too early to tell if that will be in a service pack or the next major release.

Thank you again for reporting the issue.
Posted by Mike Barry on 6/30/2010 at 12:27 PM
Is this a candidate for a service pack? I don't even know how we would begin to search this problem out.
Posted by Microsoft on 6/24/2010 at 5:15 PM
Hi Jacob,

Thank you for reporting this issue. We have confirmed that this is a bug in the CLR JIT, specifically in the inliner. As others have noted on Stack Overflow, you can work around this by assigning the value to an intermediate variable before calling IsGuid, or by forcing IsGuid not to be inlined.

Asbjørn--can you provide a code sample for the issue you're seeing?

Thanks,
Matt
Posted by Asbjørn Ulsberg1 on 6/24/2010 at 7:43 AM
I'm having this same problem with a class that inherits MarshalByRefObject through two layers of "abstract" classes. When I do 'bool isType = someClass is SomeType' and put a breakpoint right after, when the debugger breaks, 'isType' is 'false' while if I execute 'someClass is SomeType' in the debugger (immediate window or quick-watch) 'true' is returned. So at runtime, it's not discovered that 'someClass' infact inherits 'SomeType' but during debugging, it is.
Posted by Microsoft on 5/12/2010 at 10:29 PM
Thanks for your feedback. We were able to reproduce the issue you are seeing. We are routing 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.
Posted by Microsoft on 5/12/2010 at 5:04 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.