Error XDG0028 - The TypeConverter for "GridLength" does not support converting from a string

Tool: Visual Studio, Visual Studio Code, PSScriptPad, PowerShell Module
Version: 2022.5.0

Good morning. I am looking to get some help on an error I am getting when building a WPF window. I am pretty new to this, so I am confused on how to resolve this.

Here is what I am using to create the project.

Visual Studios 2022 Community Edition

PowerShell Tools for Visual Studios 2022

Here is part of my XAML where the error occurs.

<Window

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  Title="MainWindow" Height="500" Width="1000">
        <!-- Breaking window in to 2 rows -->
    <Grid>
        <!-- Main window border -->
        <Border x:Name="mainborder"
            BorderBrush="Black"
            BorderThickness="1"
            Margin="2"
            CornerRadius="3"
            Background="#eeeeee">
            <!-- Create header and working rows-->
            <Grid>
                <Grid.RowDefinitions>
                    <!-- Header row -->
                    <RowDefinition Height="50"/>
                    <!-- Working row -->
                    <RowDefinition Height="2*"/>
                </Grid.RowDefinitions>
            </Grid>
        </Border>
    <Grid>
</Window>

I am getting the following error after adding the RowDefinition heights

Error XDG0028 - The TypeConverter for “GridLength” does not support converting from a string

I am assuming that I will need to reference System.ComponentModel.TypeConverter, but does not fix Invalid Markup I am getting for the Window preview.

Any assistance would be appreciated.

Hi @themattbamba, I’ve been trying to recreate this issue but not able to. I’m also on VS2022. Your code works fine for me except for the CornerRadius which I had to remove (TypeFace issue on my end, apparently).

Are you able to get the tutorial app working? It’s not clear whether or not you are able to make any apps at all. Would you consider posting the entire project maybe?

Are you launching the .xaml.ps1 file from VS2022 when you press F5 to test?
Is it somehow possible that the CornerRadius is causing an issue for you too and that removing it would help?

Below is my working XAML which I based from the tutorial on the documentation here.

<Window

xmlns=“http://schemas.microsoft.com/winfx/2006/xaml/presentation

xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml

Title="MainWindow" Height="350" Width="525" BorderThickness="1" BorderBrush="Black" Margin="2" Background="#EEEEEE">
<Grid>
    <Grid.RowDefinitions>
        <!-- Header row -->
        <RowDefinition Height="50"/>
        <!-- Working row -->
        <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>
    <Label Content="Label" HorizontalAlignment="Left" Margin="66,60,0,0" VerticalAlignment="Top" Width="196" Grid.Row="1"/>
    <Button x:Name="myButton" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="onClick" Grid.Row="1" Margin="374,63,0,0"/>
</Grid>

If there’s no response I’m going to chalk this up to some kind of .net framework issue on the local system. Considering trying to reproduce your issue on a clean machine installation of windows with fresh installs of VS2022 and the Posh extension. This is to make sure there is not some old cached data that is not somehow causing a bug in VS2022.

Thanks @DataTraveler! Thank you for getting to this my issue, and I do agree that this is probably a localized issue for me. I will try to see if I can replicate this on another system. Anyways, here are some answers to the questions you asked.

  1. The tutorial app works fine when it is started, but when I changed it to your XAML example the issue happens again.
    This works.
Window

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  Title="MainWindow" Height="350" Width="525">

    <Grid>

        <Label Content="Label" HorizontalAlignment="Left" Margin="68,38,0,0" VerticalAlignment="Top" Width="197"/>

        <Button Content="Button" HorizontalAlignment="Left" Margin="307,41,0,0" VerticalAlignment="Top" Width="75"/>

    </Grid>

</Window>

This does not work.

<Window

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  Title="MainWindow" Height="350" Width="525">

    <Grid>
        <Grid.RowDefinitions>
            <!-- Header row -->
            <RowDefinition Height="50"/>
            <!-- Working row -->
            <RowDefinition Height="2*"/>
        </Grid.RowDefinitions>

        <Label Content="Label" HorizontalAlignment="Left" Margin="68,38,0,0" VerticalAlignment="Top" Width="197"/>

        <Button Content="Button" HorizontalAlignment="Left" Margin="307,41,0,0" VerticalAlignment="Top" Width="75"/>

    </Grid>

* List item

</Window>
```. 

2. I can post the full project, but I pivoted to creating the XAML in a C# WPF project. 

3. The app does work when I run the PowerShell script, the issue is with the preview in VS. 

4. From what I can tell, VS cannot convert the grid row definition's height froma string to an integer. 

Once again, this is probably an issue locally on my machine, but I will add another update after I am able to test it. Thanks again.

Hi @themattbamba, I was able to reproduce the issue. I removed the grid row definitions and added them back in using the UI. Please see the gif. I hope this helps.

forum_7174c

Thanks! I will try that out.

@DataTraveler This seems to help until I insert another element or start typing into the xaml editor.

The designer stops complaining if the column/rowdefinitions are set last.

Hey @themattbamba,

I’m having the same issue on Visual Studio 2022 and PowerShell Pro Tools plugin 2022.9.0.
This does not seem environmental as issue appears right after adding Grid with variable side to new WPF Window in PowerShell project.

I was able to workaround it by editing pssproj project file and adding reference to system DLL.
Excerpt from my project file:

(...)
  <ItemGroup>
    <Reference Include="System" /> <!-- This line was added -->
    <Reference Include="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <Name>mscorlib</Name>
      <AssemblyName>mscorlib.dll</AssemblyName>
      <HintPath>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll</HintPath>
    </Reference>
    <Reference Include="PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <Name>PresentationCore</Name>
      <AssemblyName>
      </AssemblyName>
      <HintPath>
      </HintPath>
    </Reference>
(...)

Note line <Reference Include="System" /> added before any existing references.
After project reload visual design window immediately started to work.

Hope it helps.

Thanks for the follow up on this. I didn’t end up using this method but will test it out. If I have any other questions/issues I will update this thread. Thanks again.