Author Topic: WPF Invalid program error  (Read 3327 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4102
  • C3D user & customizer
WPF Invalid program error
« on: November 25, 2023, 06:24:52 PM »
Can anyone shed some light on why this error is popping up on my WPF Window?
   Common Language Runtime detected an invalid program.
The project builds and the Window displays correctly, so I think this is just a VS issue, but quite annoying.

This is the XAML for the UserControl, which is nearly identical to the 3 UserControls which follow in the Window.
Code - XML: [Select]
  1. <UserControl x:Class="Quux.AcadUtilities.WPF_QSControls.SelectColorQSControl"
  2.             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5.             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.             xmlns:local="clr-namespace:Quux.AcadUtilities.WPF_QSControls" d:DataContext="{d:DesignInstance Type=local:SelectColorQSControl}"
  7.             mc:Ignorable="d"
  8.             d:DesignHeight="35" d:DesignWidth="220">
  9.     <UserControl.Resources>
  10.         <Image x:Key="PickInDwg" Source="pack://application:,,,/Quux.AcadUtilities;component/Resources/PickInDrawing.png"/>
  11.     </UserControl.Resources>
  12.     <Grid Margin="2" HorizontalAlignment="Stretch">
  13.         <Grid.ColumnDefinitions>
  14.             <ColumnDefinition Width="30"/>
  15.             <ColumnDefinition Width="80"/>
  16.             <ColumnDefinition Width="*"/>
  17.         </Grid.ColumnDefinitions>
  18.         <Grid.RowDefinitions>
  19.             <RowDefinition Height="Auto"/>
  20.         </Grid.RowDefinitions>
  21.         <Button x:Name="PickColor"  Content="{StaticResource PickInDwg}" Grid.Column="0" Margin="3" Click="PickColor_Click"/>
  22.         <StackPanel Orientation="Horizontal" Grid.Column="1" >
  23.             <TextBlock Text="Color:" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3"/>
  24.             <Button x:Name="b_ColorSelect" Margin="3" Background="{x:Null}" BorderBrush="{x:Null}" Width="30" Click="b_ColorSelect_Click">
  25.                 <Rectangle Margin="0" Fill="{Binding FillBrush}" Height="20" Width="20" Stroke="Black" RadiusX="9" RadiusY="9"/>
  26.             </Button>
  27.         </StackPanel>
  28.         <TextBox Grid.Column="2"  Text="{Binding ColorVal, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="5"/>
  29.     </Grid>
  30. </UserControl>
  31.  

n.yuan

  • Bull Frog
  • Posts: 350
Re: WPF Invalid program error
« Reply #1 on: November 26, 2023, 01:47:11 PM »
You may want to try to remove the reference to "DataContext", that is, remove:

d:DataContext="{d:DesignInstance Type=local:SelectColorQSControl}"

The DataContext type (SelectColorQSControl) probably contain types that are not instantiable at visual design time (e.g. in the VS Designer), such as types from AutoCAD .NET API namespaces, maybe?