Bug 11323 - Error message for missing type constraint confusing (mismatch with Visual Studio)
Summary: Error message for missing type constraint confusing (mismatch with Visual Stu...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-03-21 12:50 UTC by Stuart Lodge
Modified: 2013-03-21 14:32 UTC (History)
1 user (show)

Tags:
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:
Status:
RESOLVED FIXED

Description Stuart Lodge 2013-03-21 12:50:46 UTC
Short version:
- XS - The type arguments for method cannot be inferred...
- VS - The type TTarget must be a reference type in order to user it as parameter...

Longer version:

When trying to build a method:

		public static void Bind<TTarget, TSource>(this IMvxBindingContextOwner bindingOwner,
		                                          TTarget target,
		                                          string eventOrPropertyName,
		                                          Expression<Func<TSource, object>> sourcePropertyPath,
		                                          string converterName,
		                                          object converterParameter = null,
		                                          object fallbackValue = null,
		                                          MvxBindingMode mode = MvxBindingMode.Default)
		{
			var converter = ValueConverterLookup.Find(converterName);
			bindingOwner.Bind(target, eventOrPropertyName, sourcePropertyPath, converter, converterParameter,
			                  fallbackValue, mode);
		}

which called a method

        public static void Bind<TTarget, TSource>(this IMvxBindingContextOwner bindingOwner,
                                                  TTarget target,
                                                  string eventOrPropertyName,
                                                  Expression<Func<TSource, object>> sourcePropertyPath,
                                                  IMvxValueConverter converter = null,
                                                  object converterParameter = null,
                                                  object fallbackValue = null,
                                                  MvxBindingMode mode = MvxBindingMode.Default)
            where TTarget : class
        {
            // do stuff
        }

then the compiler correctly generated an error, but didn't generate the error I expected (as a VS user).

It generated:

/Users/stuartlodge/Documents/GitHub/Mvx/MvvmCross/Cirrious/Cirrious.MvvmCross.Binding/BindingContext/MvxBindingContextOwnerExtensions.Expressions.cs(38,38): Error CS0411: The type arguments for method `Cirrious.MvvmCross.Binding.BindingContext.MvxBindingContextOwnerExtensions.Bind<TTarget,TSource>(this Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextOwner, TTarget, string, System.Linq.Expressions.Expression<System.Func<TSource,object>>, string, object, object, Cirrious.MvvmCross.Binding.MvxBindingMode)' cannot be inferred from the usage. Try specifying the type arguments explicitly (CS0411) (Cirrious.MvvmCross.Binding)

But from VS use I would expect an error about "The type TTarget must be a reference type in order to user it as parameter TTarget in the generic type or method"
Comment 1 Stuart Lodge 2013-03-21 13:00:47 UTC
In case there was any doubt... this is minor...!
Comment 2 Marek Safar 2013-03-21 14:05:45 UTC
I need complete repro how to reproduce the issue
Comment 3 Stuart Lodge 2013-03-21 14:08:54 UTC
Here is one repro for you - **but it's not small**.

You can get this by downloading mvvmcross v3 - https://github.com/slodge/MvvmCross/tree/v3

and then removing line 164 to regenerate the bug - https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding/BindingContext/MvxBindingContextOwnerExtensions.Expressions.cs#L164

If you need smaller... then I don't have time right now - so this will sit in NEW
Comment 4 Marek Safar 2013-03-21 14:25:54 UTC
Mono 3.0 gives following error

BindingContext/MvxBindingContextOwnerExtensions.Expressions.cs(167,26): error CS0452: The type `TTarget' must be a reference type in order to use it as type parameter `TTarget' in the generic type or method `Cirrious.MvvmCross.Binding.BindingContext.MvxBindingContextOwnerExtensions.Bind<TTarget,TSource>(this Cirrious.MvvmCross.Binding.BindingContext.IMvxBindingContextOwner, TTarget, string, System.Linq.Expressions.Expression<System.Func<TSource,object>>, Cirrious.CrossCore.Converters.IMvxValueConverter, object, object, Cirrious.MvvmCross.Binding.MvxBindingMode)'
Comment 5 Stuart Lodge 2013-03-21 14:32:48 UTC
My about shows I'm running 2.10.12

So mark this as already fixed in 3 ;)

Thanks :)