Error in a .g.cs file?

Viewed 60351
Error   1   The type or namespace name 'BreadcrumbLib' could not be found (are you missing a using directive or an assembly reference?) YOU_CAN'T_KNOW_THE_PATH_OR_NAME.g.cs    16  7   someWPFapp

And the troublesome line is:

using BreadcrumbLib;

Yesterday I have removed that project (BreadcrumbLib) from my solution and the main project worked fine.
Today it doesn't work.

What can I do about this?
What piece of forsaken information makes Visual Studio or whatever program builds the .g.cs files put that reference there?

13 Answers

Just got this error message.

None of the answer here solved my issue, but I looked at my warnings message and saw that one of the project was build in .NET 4.7 and the other in 4.5. I put all project on the same version, build and now I'am happy!

I had this issue as well. For me the problem was that a rename didn't go through all the way in the razor files, so the g.cs files kept getting generated with the old name.

I solved it by checking the related .razor file for errors and fixing them manually.

This just happened to me. My issue was that I had spaces in my x:Name. Once I removed the spaces and cleaned the solution it worked fine.

Incorrect

<button Text="Check In" x:Name="Check In">

Correct

<button Text="Check In" x:Name="CheckIn">

I just experienced the same issue,

I had a custom control i created in a nuget, and the generated xmal class just didn't like the namespace involved. It turns the control had a namespace of xxx.yyy.zzz.Name and my project had a namespace in it, eee.fff.yyy... (notice the yyy) it just got completely confused and the only recourse was to refactor the namespaces in the parent app.

My case is a little different. I have a WPF project and I've created a custom Panel like this:

using System;
using System.Windows;
using System.Windows.Controls;

namespace MegaMenu
{
    public class MegaMenu : Panel
    {

My .xaml file looks like this:

<Window x:Class="MegaMenu.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:local="clr-namespace:MegaMenu"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"

        >
    <local:MegaMenu>
        <TextBox Width="50" Height="20" Text="First"></TextBox>
        <TextBox Width="50" Height="20" Text="Second"></TextBox>
        <TextBox Width="50" Height="20" Text="Third"></TextBox>
        <TextBox Width="50" Height="20" Text="Fourth"></TextBox>
        <TextBox Width="50" Height="20" Text="Fifth"></TextBox>
        <TextBox Width="50" Height="20" Text="Sixth"></TextBox>
        <TextBox Width="50" Height="20" Text="Seventh"></TextBox>
    </local:MegaMenu>
</Window>

This give's me the error in g.cs file blah blah. So it seems this issue happens when the namespace name is the same as the class name. I have to change them to below which caused the error gone.

.cs file
using System;
using System.Windows;
using System.Windows.Controls;

namespace MegaMenu
{
    public class MegaMenuPanel : Panel
    {
xaml file
<Window x:Class="MegaMenu.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:local="clr-namespace:MegaMenu"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"

        >
    <local:MegaMenuPanel>
        <TextBox Width="50" Height="20" Text="First"></TextBox>
        <TextBox Width="50" Height="20" Text="Second"></TextBox>
        <TextBox Width="50" Height="20" Text="Third"></TextBox>
        <TextBox Width="50" Height="20" Text="Fourth"></TextBox>
        <TextBox Width="50" Height="20" Text="Fifth"></TextBox>
        <TextBox Width="50" Height="20" Text="Sixth"></TextBox>
        <TextBox Width="50" Height="20" Text="Seventh"></TextBox>
    </local:MegaMenuPanel>
</Window>

In my case , I was tried to name a xaml control using x:Name , and forgot , and kept it as x:Name="" . The compiler was keep on throwing error. Give proper name or remove that empty string solves the error for me.

I was not using WPF but got this error because I forgot to change the namespace in the @inject part of my razor view.

I got this error down grading a .NET 6 project to .NET 4.8.

By default .NET 6 added into my .csproj <ImplicitUsings>enable</ImplicitUsings> which if I removed forced me add the using statements manually which resolved my issue of a phantom using thinking it was needed when it wasn't and couldn't be found.

Related