Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friend,

I'm facing a problem when creating a new c# WPF project in Microsoft Visual Studio 2010.
The following is my coding is xaml,
<Window x:Class="OfflineCartHMI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        
    </Grid>
</Window>

The following is the C# code in MainWindow.xaml.cs
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace OfflineCartHMI
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}


Everything looks fine but it show the following error:
The type 'Window' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

The type 'Grid' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.	

Anyone has any ideas to solve this problem?
Posted
Updated 23-Jul-15 15:37pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Jul-15 22:02pm    
Well, something is screwed up, but you did not provide the information to see what. But maybe this is not really needed. If you create a brand-new project of any of the predefined project templates, it should build immediately. But a template or something else could be broken. It does not matter what it is exactly, you need to have a consistent product. But even if this is the case, you can always make the project build manually, through understanding how it works. Believe me, minimal WPF project is not so hard to understand and fix.
—SA
ChongMing 24-Jul-15 1:05am    
Yes, this is a brand new WPF project, just click File -> New -> Project, select WPF templates under C#. Click OK button, then this error immediately show up and design faced loading problem.

May be my project templates are broken or what. I create another VB WPF project, i saw the same error...
Sergey Alexandrovich Kryukov 24-Jul-15 1:16am    
Then something in Visual Studio or even .NET is broken. You need to start reinstalling it.
—SA
Wendelius 24-Jul-15 0:18am    
In the references do you have a reference to PresentationFramework?
ChongMing 24-Jul-15 0:56am    
Yes, here is PresentationFramework in my references.

1 solution

Please see my comment to the question.

You can always fix the errors you reported if you simply make sure you added the following assemblies to references: System (System.Code also recommended), PresentationCore, PresentationFramework and WindowBase. The referenced are added from GAC (the tab ".NET" of the "Add Reference" window). That's it. Isn't that simple?

If your VS installation or some of the templates are broken, try to reinstall everything. If you accidentally lost some references or inherited some inconsistent project, fix it or build from scratch and add you source files. And so on…

—SA
 
Share this answer
 
Comments
ChongMing 24-Jul-15 1:00am    
Thanks SA, I have all the references that you mentioned:System (System.Code also recommended), PresentationCore, PresentationFramework and WindowBase.

I had tried to create another VB WPF project, i faced the same error, may be I'm needed to re-install my visual studio.
Sergey Alexandrovich Kryukov 24-Jul-15 1:13am    
Say, "Window" is from "PresentationFramework"; and its type System.Windows.Window. You cannot have it and get this error. Anyway, I don't have your environment and all code. Something is broken.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900