Error in UWP app
Windows 10 UWP app, submitted to the store, produces an error:
Cannot add instance of type 'Cimbalino.Toolkit.Behaviors.MultiBindingBehavior' to a collection of type 'Microsoft.Xaml.Interactivity.BehaviorCollection'.
On dev machine (in debug mode) everything works fine.
Lib version 2.4.1
Stacktrace of the error (only happens in release mode)
System.NullReferenceException: Arg_NullReferenceException
at Cimbalino.Toolkit.Behaviors.MultiBindingBehavior.Update() in D:\Users\Pedro\Dropbox\Projects\Cimbalino.Toolkit\src\cimbalino.toolkit (wp8)\behaviors\MultiBindingBehavior.cs:line 212
at Cimbalino.Toolkit.Behaviors.MultiBindingBehavior.OnAttached() in D:\Users\Pedro\Dropbox\Projects\Cimbalino.Toolkit\src\cimbalino.toolkit (wp8)\behaviors\MultiBindingBehavior.cs:line 166
at Microsoft.Xaml.Interactivity.Behavior.Attach(DependencyObject associatedObject)
at Microsoft.Xaml.Interactivity.BehaviorCollection.VerifiedAttach(DependencyObject item)
at Microsoft.Xaml.Interactivity.BehaviorCollection.BehaviorCollection_VectorChanged(IObservableVector1 sender, IVectorChangedEventArgs eventArgs) at Windows.Foundation.TypedEventHandler2.Invoke(TSender sender, TResult args)
at __Interop.Intrinsics.HasThisCall__22[TArg0](Object __this, IntPtr pfn, Object arg0, TArg0 arg1)
at __Interop.ReverseComStubs.Stub_5[TArg0,TArg1](Object __this, Void* unsafe_d, Void* unsafe_e, IntPtr __methodPtr)
The error seems to disappear if I uncheck Project properties -> Build -> Optimize code
What version of Visual Studio are you using? Are you using the correct UWP XAML Behaviors (the one from this NuGet)?
Visual Studio 2017.
In my project.lock.json there is
"Cimbalino.Toolkit/2.4.1": { "type": "package", "dependencies": { "Cimbalino.Toolkit.Core": "2.4.1", "Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0" },
Only Cimbalino.Toolkit is referenced directly in the project References
Please try to manually add the Microsoft.Xaml.Behaviors.Uwp.Managed package to your project and see if that makes any difference.
Manually adding Microsoft.Xaml.Behaviors.Uwp.Managed package does not make any difference.
If "Compile with .NET Native tool chain" and "Optimize code" are checked, I get this error. Unchecking those is a workaround.
~Oh, I just noticed you're using the MultiBindingBehavior: That's not available in UWP!!~
Please ensure you add Cimbalino.Toolkit to all your projects that actually require it, it should then pick the correct assembly according to the platform!
How come it is not available? I've been using it for quite some time. What should I use instead?
For example, this article says it's available:
http://www.damirscorner.com/blog/posts/20160221-MultibindingInUniversalWindowsApps.html
Sorry, though I wrote MultiBindingBehavior I was thinking on MultiApplicationBarBehavior; it's been a long day, so please just disregard my last comment...
I now start to remember this better, and you are correct when you say that this issue goes away when disabling .NET Native: the problem is that this behavior relies heavily on reflection and as such, can have .NET Native problems.
I need to research this further, but I'd advise in using compiled bindings (x:bind) function support as an alternative!
@dmitry-lt can you share the XAML bit you have with this MultiBindingBehavior ?
<Image VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0 5 0 5" Width="50" Height="50">
<interactivity:Interaction.Behaviors>
<behaviors:MultiBindingBehavior Converter="{StaticResource IconConverter}" PropertyName="Source">
<behaviors:MultiBindingItem Value="{Binding Item}" />
<behaviors:MultiBindingItem Value="{Binding Item.Enabled}" />
<behaviors:MultiBindingItem Value="{Binding Item.Status}" />
<behaviors:MultiBindingItem Value="{Binding Item.Type}" />
</behaviors:MultiBindingBehavior>
</interactivity:Interaction.Behaviors>
</Image>
Ok, the solution will be to add a runtime exception so that we can use reflection over Image.Source property.
On the solution explorer, there's a Properties node in the UWP project for your app - expand it!
Inside you should find a Default.rd.xml file. Find where it says "" and add the following line below it:
<Type Name="Windows.UI.Xaml.Controls.Image" Dynamic="Required All" Serialize="Require All" />
Rebuild the app with the "Compile with .NET Native tool chain" and "Optimize code" checked, and check again!
Hmm. There is no Default.rd.xml in my project. Anyway, I have already changed my code to not use MultiBindingBehavior (and handle it in view model instead).
Same here, similar XAML, same problem (only when compiling in release mode)

Installing 'Microsoft.Xaml.Behaviors.Uwp.Managed' v2.0.0 manually (instead of v1.1.0) did not help. Using the v2.5.0 version of the toolkit, on a UWP project