question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typeInfo.GetCustomAttribute<ContentPropertyAttribute>() returns null

See original GitHub issue

I have migrated a Windows Store 8.1 application to UWP using this guide from Windows. During this migration process It was required to remove all existing project references and to manually install them again using Nuget. (Previously installed version- 2.0.2) But when I install the latest version from Nuget (Version - 3.2.0) I’m getting the following error when opening popups. exception 3 2 0

Code used to create and open Popups

public virtual void ShowPopup(object rootModel, object context = null, IDictionary<string, object> settings = null)
        {
            var popup = this.CreatePopup(rootModel, settings);
            var view = ViewLocator.LocateForModel(rootModel, popup, context);

            popup.Child = view;
            popup.SetValue(View.IsGeneratedProperty, true);
            ViewModelBinder.Bind(rootModel, popup, null);
            Caliburn.Micro.Action.SetTargetWithoutContext(view, rootModel);

            var activatable = rootModel as IActivate;
            if (activatable != null)
            {
                activatable.Activate();
            }

            var deactivator = rootModel as IDeactivate;
            if (deactivator != null)
            {
                popup.Closed += (object sender, object e) => { deactivator.Deactivate(true); };
            }

            popup.IsOpen = true;
        }

However I was able to clone this repository and debug to the point of exception. It seems that this particular code (line 390) in View.cs returns null. var contentProperty = typeInfo.GetCustomAttribute<ContentPropertyAttribute>(); But when I replaced the current code with the corresponding code snippet in 2.0.2 (line 362) It works perfectly.

var contentProperty = typeInfo.CustomAttributes
                .FirstOrDefault(a => a.AttributeType == typeof(ContentPropertyAttribute));

            return contentProperty == null ?
                DefaultContentPropertyName :
                contentProperty.NamedArguments[0].TypedValue.Value.ToString();

I would like to know if there is a workaround. Thanks in advance.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nigel-sampsoncommented, Feb 19, 2019

Thanks for the extra info.

0reactions
mohamedraqeebcommented, Feb 15, 2019

The following is the XAML template we used for the Popup. All the popups in the application are similar to this. The type of Popup used is

Windows.UI.Xaml.Controls.Primitives.Popup

.I assume that this is what you are looking for, or else please let me know.

<UserControl
    x:Class="Items.Assets.AssetInfoView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Items.Assets"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <UserControl.Resources>
        <Style x:Key="AssetInfoListView" TargetType="ListViewItem">
            <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
            <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="TabNavigation" Value="Local"/>
            <Setter Property="IsHoldingEnabled" Value="True"/>
            <Setter Property="Margin" Value="0,0,18,2"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Top"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <ListViewItemPresenter 
                            CheckBrush="#FF2E41FF" 
                            ContentMargin="4" 
                            ContentTransitions="{TemplateBinding ContentTransitions}" 
                            DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" 
                            DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" 
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                            Padding="{TemplateBinding Padding}" 
                            PointerOverBackgroundMargin="0,0,0,5" 
                            PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
                            PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" 
                            ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" 
                            SelectionCheckMarkVisualEnabled="True" SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" 
                            SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" 
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
                            SelectedBackground="Transparent"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid
        Width="340"
        Height="455"
        Opacity="0.99">

        <Grid.RowDefinitions>
            <RowDefinition Height="10"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>

        <Viewbox 
            Grid.Row="0"
            Width="30" Margin="90,0,0,0">
            <Path Data="m 10,0 L 0,10 20,10 Z" Fill="#f2f2f2" Opacity="0.99" Margin="0"></Path>
        </Viewbox>

        <Grid 
            Grid.Row="1" VerticalAlignment="Top">
            <Border
                Width="340"
                Height="445"
                Background="#f2f2f2"
                CornerRadius="15"
                Opacity="0.99">

                <Grid
                    Background="Transparent">

                    <Grid.RowDefinitions>
                        <RowDefinition Height="45"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>

                    <TextBlock 
                        Grid.Row="0" 
                        Text="{Binding AssetInfoTitle}" 
                        FontSize="21" 
                        HorizontalAlignment="Center" 
                        Foreground="{StaticResource AppTitleFontColor}"
                        VerticalAlignment="Center" Margin="0,0,0,1"/>

                    <ListView 
                        Grid.Row="1" 
                        ItemsSource="{Binding AssetInfoList}" 
                        Height="400"
                        Width="340"
                        IsItemClickEnabled="False" 
                        ItemContainerStyle="{StaticResource AssetInfoListView}" 
                        VerticalAlignment="Top" 
                        BorderBrush="#b8b8b8" BorderThickness="0,1,0,0"
                        SelectionMode="None"
                        Padding="15,0,0,0">

                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Border BorderBrush="#c9c7c7" BorderThickness="0,0,0,1">
                                    <Grid MinHeight="37" Width="305">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                                            <ColumnDefinition Width="*"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock
                                            Grid.Column="0"
                                            FontSize="18" 
                                            Text="{Binding Name}" 
                                            FontWeight="Bold"
                                            Margin="0,0,5,0"
                                            MaxWidth="200"
                                            HorizontalAlignment="Left"
                                            TextTrimming="CharacterEllipsis">
                                        </TextBlock>
                                        <TextBlock
                                            Grid.Column="1"
                                            FontSize="18" 
                                            Text=":" 
                                            FontWeight="Bold"
                                            HorizontalAlignment="Left">
                                        </TextBlock>
                                        <TextBlock
                                            Grid.Column="2"
                                            FontSize="18" Width="Auto"
                                            Text="{Binding Value}" TextWrapping="WrapWholeWords" HorizontalAlignment="Left">
                                        </TextBlock>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </Grid>

            </Border>
        </Grid>
    </Grid>
</UserControl>
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Can GetTypeInfo ever return null?
Since TypeInfo is a refactoring of some of what was originally covered by Type , and Object.GetType() is never expected to return null...
Read more >
TypeInfo.GetDeclaredProperty(String) Method
Returns an object that represents the specified property declared by the current type. ... TypeInfo.GetDeclaredProperty(String) Method ... name is null .
Read more >
c# - What's wrong with returning null?
I've recenlty been greeted by CS8603 - Possible null reference return, which indicates that my code could possibly return null . It's a...
Read more >
typeid operator
contains some type's information, generated by the implementation. This is the class returned by the typeid operator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found