Answered Cannot create unknown type '{CLR -- error in WPF

  • Monday, September 24, 2012 5:24 PM
     
     

    Hi,

    I am working on one WPF application. In this I am loading main window XAML in run time and Application_Start event.

    I the main window I am initializing an object in Window.Resource.

    <Window 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:data="clr-namespace:ExpnseManager.DataAccess"
            Title=".::Expense Manager::." Height="750" Width="750">
        <Window.Resources>
            <data:ExpesneManagerDataAccess x:Key="aa" />
        </Window.Resources>

    Here I am getting error - Cannot create unknown type '{CLR

All Replies

  • Monday, September 24, 2012 6:05 PM
     
     
    Check whether ExpesneManagerDataAccess class is available in ExpnseManager.DataAccess. There could be some mistake in typing.

    Gaurav Khanna | Microsoft VB.NET MVP

  • Tuesday, September 25, 2012 2:36 AM
    Moderator
     
     

    xmlns:data="clr-namespace:ExpnseManager.DataAccess"

    <data:ExpesneManagerDataAccess x:Key="aa" />

    Expesne or Expnse, they are different.


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Tuesday, September 25, 2012 8:42 AM
     
     

    Hi Gaurav,

    Problem is not with the typing spelling, otherwise it wont compile.

    However I have checked all spellings and corrected as it was creating confusion.

    Thanks,

    Nitin

  • Tuesday, September 25, 2012 8:44 AM
     
     

    Hi,

    ExpnseManager.DataAccess is the namespace.

    ExpesneManagerDataAccess is the class under this namespace.


    Thanks,

    Nitin

  • Tuesday, September 25, 2012 1:08 PM
     
      Has Code

    Hi,

    Is the ExpenseManager.DataAccess in another project? If it is then you need to change your reference to add that information -

    xmlns:data="clr-namespace:ExpnseManager.DataAccess;assembly=AssemblyName"

  • Tuesday, September 25, 2012 3:11 PM
     
     
    It is in same project.
  • Tuesday, September 25, 2012 3:16 PM
     
     

    It doesn't sound as though you have a peroblem referencing the class. Have you tried to debug into the ExpesneManagerDataAccess to see if anything in there is causing an exception?

  • Tuesday, September 25, 2012 4:38 PM
     
     

    Hi,

    I tried that, in fact I tried with just empty class, it is not working.

    And one more thing if I don't load XAML in run time i.e. using StartUpURI in App.Config , it is working.

    In my project I have deleted the Main.Xaml.cs class and loading main.xaml in run time from Application_start event and in main.xaml intializing this class(ExpesneManagerDataAccess ) instance.

    I hope it clears my problem.

    Thanks,

    Nitin

  • Wednesday, September 26, 2012 6:23 AM
    Moderator
     
     

    Hi Nitin,

    I still cannot reproduce the issue. Could you please share a minimum about this issue so that we can reproduce the issue locally?

    Thank you!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, September 26, 2012 9:20 AM
     
     

    Below Steps:

    1. Create a new WPF Project

    2. Delete MainWindow.xaml.cs (Code Behind Class)

    3. Delete this class reference from MainWindow.xaml file( Just beside <Window tag in MainWindow.xaml)

    4. Open App.xaml, replace StartUri with StartUp event

    Startup="Application_Startup"

    5. In the App.xaml.cs

    private void Application_Startup(object sender, StartupEventArgs e)
     {
           Window window = XamlReader.Load(new FileStream(@"MainWindow.xaml",FileMode.Open)) as Window;
           window.Show();

     }

    6. Run the code it works fine.

    7. Now add a new folder in Project say DataAccess

    8. Add a new class in this folder say DataManager or whatever name you give.

    9. Create this instance MainWindow.xaml

    <Window 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:data="clr-namespace:TestDeleteApp.DataAccess"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <data:TestDataAccess x:Key="a" />
        </Window.Resources>

    10. Now run the application, it gives error.

  • Wednesday, September 26, 2012 9:38 AM
    Moderator
     
     Answered Has Code

    Hi Nitin,

    This makes your xaml file become "loose xaml". And you can no longer omit the assembly name in the namespace mapping.

    xmlns:data="clr-namespace:TestDeleteApp.DataAccess;assembly=AssemblyName"

    Best regards,

    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, September 26, 2012 10:26 AM
     
     

    Wow!! It worked. Thanks :)