This is a migrated thread and some comments may be shown as answers.

Silverlight crash opening Context menu

7 Answers 154 Views
Menu
This is a migrated thread and some comments may be shown as answers.
VH
Top achievements
Rank 1
VH asked on 09 Mar 2012, 08:41 AM
Hi,
We have a problem with a context menu, which is created and filled exclusively in code. Sometimes, the whole application crashes when the context menu is about to be displayed. Often the error can't be tracked as the application crashes completely. However sometimes we can track an error message which I think is related to the issue:

   bei MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)

   bei MS.Internal.XcpImports.MethodEx(DependencyObject obj, String name)

   bei MS.Internal.XcpImports.FrameworkElement_ApplyTemplate(FrameworkElement frameworkElement)

   bei System.Windows.Controls.Control.ApplyTemplate()

   bei Telerik.Windows.Controls.RadMenuItem.ChangeTemplate(MenuItemRole role)

   bei Telerik.Windows.Controls.RadMenuItem.UpdateRole()

   bei Telerik.Windows.Controls.RadMenuItem.OnLoaded(Object sender, RoutedEventArgs e)

   bei MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)

   bei MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

  

   Failed to assign to property  'System.Windows.Controls.ContentPresenter.Content'. [Line: 476 Position: 83]

 

I believe that it hast to do with initializing the context menu because once the menu has been opened the error will not appear anymore.  But most of the time it workes so it is hard to reproduce the error (It always works when I step thorough the code in debug mode). 
Could you give us any hints what could be the matter?
Thanks a lot
Volkmar

 

7 Answers, 1 is accepted

Sort by
0
Boyan
Telerik team
answered on 14 Mar 2012, 09:56 AM
Hi Martin,

We are not aware of such an error and we are not able to reproduce the bad behavior. Could you please send us a sample code or project where the error can be reproduced. Also could you please tell us if you are using SL4 or SL5 binaries.

Regards,
Boyan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jamest
Top achievements
Rank 2
answered on 29 Mar 2012, 09:03 PM
I am experiencing the same thing with Silverlight 4 binaries (can't try 5) in both the 2012 Q1 and sp1 binaries. Were you able to figure out a work around? I have a RadMenu and Context menus that build contextually depending on the item selected. They are built in code behind in a large switch case (gasp). They load properly for first item use, as soon as it goes to open again  after I clear the items and load them again the app crashes . Another thing is that my items aren't bound and this scenario has been working since silverlight 3 releases. Same result with black(default), windows 7, and silver themes.

Line: 453
Error: Sys.InvalidOperationException: Invalid XAML for control 'MMSMSL'. [] (line 512, col 65): Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'.
0
VH
Top achievements
Rank 1
answered on 30 Mar 2012, 08:27 AM
Yes there is a workaround.
Create your RadMenu object with a dummy-item (inclusive all submenus).
After that add the RadMenuItems you need and remove the dummy finally.
It works for me. Hope this helps!
0
Jamest
Top achievements
Rank 2
answered on 30 Mar 2012, 04:47 PM
MH -Thank you for your feedback. I tried that and it worked with limited success. The error is no longer thrown right away, but still occurs with normal usage. I have nested context menus, and a radmenu item dynamically populated on selection of an item. So sometimes it is opened and other times its not.  I have submitted a support ticket as all of this has been working up until this last release. I had done a work around awhile back to get around the having to add a dummy child by setting the main menuitem's header to null, clearing its sub-items, and then reassigning the header. I appreciate your time and have a great weekend.

   Thanks, Jordan
0
Stefan Falz
Top achievements
Rank 1
answered on 31 Mar 2012, 01:50 AM
Hi Boyan,

please take a look at the following thread. I think the reason for this error is the same or at least a similar one as described in the othert thread.

  http://www.telerik.com/community/forums/silverlight/richtextbox/problem-with-image-inside-richtextbox.aspx

IMHO the problem has nothing to do with user defined context menus because the integrated context menus in RadRichTextBox (at least the image context menus) are throwing the same exception.
0
Boyan
Telerik team
answered on 02 Apr 2012, 03:54 PM
Hi Guys,

We reproduced the problem, thanks to Ender and after some investigation we found that there is a bug in Silverlight 4 when control templates are changed and there are visual elements in the Header. The bug is fixed in SL5 and that is why it is working as expected there.

If you don't want to upgrade to Silverlight 5, we found a workaround that will work in Silverlight 4 as well. You can use DataItems instead of RadMenuItems and it will work as expected.

You can find attached  the sample project that Ender send us with the workaround applied.

Kind regards,
Boyan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jamest
Top achievements
Rank 2
answered on 02 Apr 2012, 11:57 PM
I appreciate the work around. But it would just cost too much time to do that in 12 projects. I was able to convince my team to give 5 a shot and it appears to be working. Hopefully 1000+ users don't find it too much of a hassle upgrading their client versions. Thank you,
           Jordan
Tags
Menu
Asked by
VH
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Jamest
Top achievements
Rank 2
VH
Top achievements
Rank 1
Stefan Falz
Top achievements
Rank 1
Share this question
or