Exception in LocExtension when being used by blend designer
I've been tracking down an issue in the blend designer where an exception is being thrown when rendering one of my views.
I have a user control that looks like this:
I'm using this user control in another xaml:
I have a xaml using a custom control:
and the problem I'm seeing is that an exception is being thrown from the loc extension in LocExtension.cs, line 46, in the ProvideValue function:
This is the exception being thrown:
I'm not sure what I might be doing wrong exactly. I'll keep fiddling around with the code here, but thought I'd ask here to see if I'm doing something dumb.
thanks,
sam
I have a user control that looks like this:
Code: Select all
public partial class VoiceViewSession : UserControl
{
public VoiceViewSession()
{
InitializeComponent();
}
private static readonly DependencyProperty _labelBackgroundProperty =
DependencyProperty.Register("SessionLabelBackground", typeof(Brush), typeof(VoiceViewSession), new PropertyMetadata(null));
public Brush SessionLabelBackground
{
get { return (Brush)GetValue(_labelBackgroundProperty); }
set { SetValue(_labelBackgroundProperty, value); }
}
private static readonly DependencyProperty _labelTextProperty =
DependencyProperty.Register("SessionLabelText", typeof(string), typeof(VoiceViewSession), new PropertyMetadata(null));
public string SessionLabelText
{
get { return (string)GetValue(_labelTextProperty); }
set { SetValue(_labelTextProperty, value); }
}
#if NOESIS
private void InitializeComponent()
{
NoesisUnity.LoadComponent(this);
}
#endif
}
I have a xaml using a custom control:
Code: Select all
<local:VoiceViewSession DataContext="{Binding Voice.SessionParty}" SessionLabelBackground="Purple" SessionLabelText="{noesis:Loc Text.InGame.Voice.Channel.Party}"/>
Code: Select all
public override object ProvideValue(IServiceProvider serviceProvider)
{
if (!(serviceProvider.GetService(typeof(IProvideValueTarget)) is IProvideValueTarget provideValueTarget))
{
return null;
}
DependencyObject dependencyObject = (DependencyObject)provideValueTarget.TargetObject;
DependencyProperty targetProperty = (DependencyProperty)provideValueTarget.TargetProperty; // <==== Exception being thrown here
LocMonitor locMonitor = (LocMonitor)dependencyObject.GetValue(MonitorProperty);
if (locMonitor == null)
{
locMonitor = new LocMonitor(dependencyObject);
dependencyObject.SetValue(MonitorProperty, locMonitor);
}
return locMonitor.AddDependencyProperty(targetProperty, _resourceKey);
}
Code: Select all
System.InvalidCastException
HResult=0x80004002
Message=Unable to cast object of type 'System.Reflection.RuntimePropertyInfo' to type 'System.Windows.DependencyProperty'.
Source=Noesis.GUI.Extensions
StackTrace:
at NoesisGUIExtensions.LocExtension.ProvideValue(IServiceProvider serviceProvider) in NoesisGUIExtensions\LocExtension.cs:line 46
thanks,
sam
Re: Exception in LocExtension when being used by blend designer
I'm also sometimes seeing an error on line 45:
the exception being:
Code: Select all
DependencyObject dependencyObject = (DependencyObject)provideValueTarget.TargetObject;
Code: Select all
System.InvalidCastException: 'Unable to cast object of type 'System.Windows.SharedDp' to type 'System.Windows.DependencyObject'.'
Re: Exception in LocExtension when being used by blend designer
Hi samc,
I have reproduced your issue, it is happening when ProvideValue is called for LocExtension when a template it is in is being loaded. During this call there are no valid targets, and a non-null value should be returned.
Could you create a ticket for this on our bugtacker, I'll provide LocExtension.cs with a fix for this for you to test.
Thanks!
I have reproduced your issue, it is happening when ProvideValue is called for LocExtension when a template it is in is being loaded. During this call there are no valid targets, and a non-null value should be returned.
Could you create a ticket for this on our bugtacker, I'll provide LocExtension.cs with a fix for this for you to test.
Thanks!
Who is online
Users browsing this forum: No registered users and 5 guests