Home > Enterprise >  Getting MC3074 The tag 'AssemblyPartControl' does not exist in XML namespace 'clr-nam
Getting MC3074 The tag 'AssemblyPartControl' does not exist in XML namespace 'clr-nam

Time:12-23

Like so many others, I am seeing this compile error. I am a long-time developer coming back to WPF after a number of years away.

I have a single project solution targeting net6.0-windows (switched to net5.0-windows below to test). The project was created in VS 2022 Pro. I am not specifying ;assembly= in my clr-namespace: declaration. After reading SO extensively, I believe these two conditions are the most common causes of this error.

Project

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <Nullable>annotations</Nullable>
    <UseWPF>true</UseWPF>
    <AssemblyName>NTS$(MSBuildProjectName)Boards</AssemblyName>
  </PropertyGroup>    
</Project>

UserControl

<UserControl x:Class="EndGrain.View.AssemblyPartControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vw="clr-namespace:EndGrain.View"
             xmlns:vm="clr-namespace:EndGrain.ViewModel"
             mc:Ignorable="d" 
             >
...
    <Grid Background="{StaticResource BackgroundBrush}">
...
    </Grid>
</UserControl>

UserControl code-behind

using System.Windows.Controls;

namespace EndGrain.View
{
    /// <summary>
    /// Interaction logic for AssemblyPartControl.xaml
    /// </summary>
    public partial class AssemblyPartControl : UserControl
    {
        public AssemblyPartControl()
        {
            InitializeComponent();
        }
    }
}

View

<Window x:Class="EndGrain.View.AssemblyPartSandboxView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:vw="clr-namespace:EndGrain.View"
        mc:Ignorable="d"
        Title="AssemblyPartSandboxView" Height="100" Width="200">
    <Grid>
        <vw:AssemblyPartControl Width="100" Height="30" />
    </Grid>
</Window>

What I've tried

Started with Visual Studio Professional 2022 17.0.2

- Built the project without the UserControl. Builds fine.
- Typed in the <vw:AssemblyPartControl /> element. Built the project. Error list shows the error.
- Changing the target framework back to net5.0-windows (from net6.0-windows) does not help.

Opened the net5 project with Visual Studio 2019 Enterprise 16.11.7

- Rebuilt the project. Error shows.
- Commented out the UserControl. Rebuilt. Builds fine.
- Uncommented the UserControl. Rebuilt. Error shows.

Opened with Blend for Visual Studio Enterprise 2019 16.11.7

- Dragged the UserControl to the design surface. Blend added the element with the vw namespace.
- Built the project, and the Error List shows the error.

Added ;assembly=NTSEndGrainBoards in the namespace definition, as I've overridden the default assembly name. No effect.

Hopefully a sharp set of eyes can see the stupid mistake I've made; it can't be this hard. Thank you in advance for your assistance.

CodePudding user response:

As I finished composing my question, I decided to try removing the non-standard assembly name. That did the trick. Hopefully this will be helpful to others, and thanks again for looking.

Revised Project

<Project Sdk="Microsoft.NET.Sdk">    
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <Nullable>annotations</Nullable>
    <UseWPF>true</UseWPF>
  </PropertyGroup>    
</Project>
  • Related