Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in UWP app #59

Open
dmitry-lt opened this issue Apr 3, 2017 · 15 comments
Open

Error in UWP app #59

dmitry-lt opened this issue Apr 3, 2017 · 15 comments

Comments

@dmitry-lt
Copy link

dmitry-lt commented Apr 3, 2017

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

@dmitry-lt
Copy link
Author

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)

@dmitry-lt
Copy link
Author

The error seems to disappear if I uncheck Project properties -> Build -> Optimize code

@pedrolamas
Copy link
Member

What version of Visual Studio are you using? Are you using the correct UWP XAML Behaviors (the one from this NuGet)?

@dmitry-lt
Copy link
Author

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

@pedrolamas
Copy link
Member

Please try to manually add the Microsoft.Xaml.Behaviors.Uwp.Managed package to your project and see if that makes any difference.

@dmitry-lt
Copy link
Author

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.

@pedrolamas
Copy link
Member

pedrolamas commented Apr 3, 2017

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!

@dmitry-lt
Copy link
Author

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

@pedrolamas pedrolamas reopened this Apr 3, 2017
@pedrolamas
Copy link
Member

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!

@pedrolamas
Copy link
Member

@dmitry-lt can you share the XAML bit you have with this MultiBindingBehavior ?

@dmitry-lt
Copy link
Author

dmitry-lt commented Apr 11, 2017

<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>

@pedrolamas
Copy link
Member

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!

@dmitry-lt
Copy link
Author

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).

@pulimento
Copy link

Same here, similar XAML, same problem (only when compiling in release mode)
cimbalino crash

@pulimento
Copy link

pulimento commented May 24, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants