Search code examples
wpfvisual-studio-2022

WPF: Could not load file or assembly error in the designer but application runs with no problems


To try to solve another issue with the designer I've deleted bin and obj directories. Since then I'm facing this error while being in the designer: "The error message "Could not load file or assembly 'DesktopClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the specified file.". I can run the app with no problems the error is only related to the designer. The DesktopClient assembly is the assembly of the WPF project.

I've already tried:

  • Restarting the IDE
  • Updating the IDE

The project targets .NET 8.0.

Here is XAML code:

<Window x:Class="DesktopClient.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:root="clr-namespace:DesktopClient"
        xmlns:local="clr-namespace:DesktopClient.Views"
        xmlns:viewModels="clr-namespace:DesktopClient.ViewModels"
        xmlns:controls="clr-namespace:DesktopClient.Controls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        d:DataContext="{d:DesignInstance viewModels:MainWindowViewModel, IsDesignTimeCreatable=true}">
    <Window.Resources>
        <DataTemplate x:Key="IModeViewModel">
            <StackPanel>                
                <ContentControl Content="{Binding}"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate DataType="{x:Type viewModels:OrdersListModeViewModel}">
            <!-- some content -->
        </DataTemplate>
        <!-- some content -->
</Window.Resources>

Solution

  • Sometimes intellisense gets into a bad state, and deleting the .vs folder will clear that out. It's not a super elegant solution, but it should work.

    delete the .vs folder