Bug 37824

Summary: C# 6: "?." - RuntimeBinderException: Cannot perform member binding on `null' value
Product: [Mono] Compilers Reporter: Alexander Mezhov <as.mezhov>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: ludovic, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: 4.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://bugzilla.xamarin.com/show_bug.cgi?id=37801
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: MonoDelelop screenshot

Description Alexander Mezhov 2016-01-20 04:14:36 UTC
Created attachment 14636 [details]
MonoDelelop screenshot

Hello!

I have a problem which I think relates to "bug 37801". I have reproduced the exception in the next small code block.

CODE:

> using System;
> 
> namespace BadDynamic2
> {
>     class MainClass
>     {
>         public static void Main(string[] args)
>         {
>             DoSomething(new SomeClass());
>         }
> 
>         public static string DoSomething(dynamic value)
>         {
>             return value.Property1?.Property2; // <-- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform member binding on `null' value
>         }
>     }
> 
>     public class SomeClass
>     {
>         public SomeClass2 Property1 { get; set; }
>     }
> 
>     public class SomeClass2
>     {
>         public string Property2 { get; set; }
>     }
> }

EXCEPTION:

> Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform member binding on `null' value
>  at (wrapper dynamic-method) System.Object:CallSite.Target (System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
>  at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet] (System.Runtime.CompilerServices.CallSite site, System.Dynamic.T0 arg0) [0x00127] in <filename unknown>:0 
>  at BadDynamic2.MainClass.DoSomething (System.Object value) [0x00002] in /home/ubuntu/Projects/BadDynamic2/Program.cs:16 

MONO:

> $ mono --version
> Mono JIT compiler version 4.2.1 (Stable 4.2.1.102/6dd2d0d Thu Nov 12 09:52:44 UTC 2015)
> Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
> 	TLS:           __thread
> 	SIGSEGV:       altstack
> 	Notifications: epoll
> 	Architecture:  amd64
> 	Disabled:      none
> 	Misc:          softdebug 
> 	LLVM:          supported, not enabled.
> 	GC:            sgen


XBUILD:

> $ xbuild /version
> XBuild Engine Version 12.0
> Mono, Version 4.2.1.0
> Copyright (C) 2005-2013 Various Mono authors
Comment 1 Marek Safar 2016-01-28 12:12:46 UTC
Fixed in master and Mono 4.3.2