Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:16:56+00:00 2026-06-16T00:16:56+00:00

In VS2010 create a new WPF application. In MainWindow.cs declare an unused local variable

  • 0

In VS2010 create a new WPF application.
In MainWindow.cs declare an unused local variable to generate a compiler warning like so:

namespace WpfApplication4
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            int i = 0;
        }
    }
}

Build the application. The output will appear something like this:

------ Rebuild All started: Project: WpfApplication4, Configuration: Debug x86 ------
D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\MainWindow.xaml.cs(25,8): warning CS0219: The variable 'i' is assigned but its value is never used

Compile complete -- 0 errors, 1 warnings
  WpfApplication4 -> D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\bin\Debug\WpfApplication4.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Notice that there is only one mention of unused variable ‘i’. Now in MainWindow.xaml add a reference to the local namespace like this:

<Window x:Class="WpfApplication4.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication4"
    Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

Now rebuild and the output appears like this:

------ Rebuild All started: Project: WpfApplication4, Configuration: Debug x86 ------
D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\MainWindow.xaml.cs(25,14): warning CS0219: The variable 'i' is assigned but its value is never used

Compile complete -- 0 errors, 1 warnings
MainWindow.xaml.cs(25,14): warning CS0219: The variable 'i' is assigned but its value is never used
  WpfApplication4 -> D:\_UserData\Development\Workspaces\DotnetTesting\WpfApplication4\WpfApplication4\bin\Debug\WpfApplication4.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Notice that now there are two mentions of unused variable ‘i’.

Why is that and how do I stop it from happening?

EDIT

I’ve worked out how to make it stop. Just add the name of the local assembly as well as the namespace like so:

<Window x:Class="WpfApplication4.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication4;assembly=WpfApplication4"
    Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>

Unfortunately that isn’t a solution since in a WPF exe when refering to a namespace in the local assembly you you are not allowed to supply the name of the assembly in the namespace declaration. This will build, but if you try to reference a type in the local assembly it will fail if the assembly name is specified. Using the xmlns:local=”clr-namespace:WpfApplication4;assembly=” syntax the double warnings return.

P.S. Why the down voting? Down voting without comment is lame, how am I supposed to improve the question if you don’t tell me what you don’t like about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:16:57+00:00Added an answer on June 16, 2026 at 12:16 am

    It’s because it’s a bug in VS2010 that MS won’t fix.

    https://connect.microsoft.com/VisualStudio/feedback/details/763045/adding-a-xaml-namespace-reference-to-containing-assembly-corrupts-build-output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing these steps: Create new vs2010 C# console application Project menu -> Add
I was on the process of starting a new WPF application with VS2010 beta
I am using VS2010 to create a new unit test project to test my
I need to create some dynamic menus in a VS2010 SDI application I'm writing.
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
I am about to create a new developer PC image for developing WPF applications
When I create a new project of any kind (winforms app/classlib ..) using VS2010
I recently installed VS2010 beta 2 and tried to create a new Visual C++
(using VS 2010) I'm new to WPF and am trying to create a TreeViewItem
I am attempting to create a new Database Project in VS2010 via the New

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.