locked
failure of clr-namespace resolution in 2008 C# Express w Orcas RRS feed

  • Question

  • Namespaces defined with clr-namespace fail to get resolved in the IDE and show up with a "Could not create instance of type "xxxxx".  (Where the class xxxxx is clearly defined in the namespace referenced in the clr-namespace entry.)

     

    The code in question was downloaded from a sample in code project referencing "Master Pages".  But, a similar example from another person whose code I trust very much also fails to resolve the classes within the namespaces referenced by the clr-namespace directive.

     

    Is this a limitation of the Express version?  Or is there some other issue I am not aware of?

     

    Thanks

    Tuesday, September 11, 2007 5:37 PM

Answers

  • You're just trying to use a WPF UserControl in your application, so it's certainly not a limitation of C# Express. I just loaded up C# Express Beta2, created a WPF app, added a WPF UserControl to that app (right-click on project, select Add New Item, WPF User Control), then used the control in the main Window of that app (added the xmlns attribute and subsequent reference to the control manually). So it is possible - here's the XAML:

     

    <Window x:Class="WpfApplication1.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:WpfApplication1"

    Title="Window1" Height="300" Width="300">

    <Grid>

    <local:UserControl1/>

    </Grid>

    </Window>

     

    I did run into some weirdness where the designer didn't refresh after I added the new control - it continued to complain (in the XML with blue squiggles) that it couldn't find the control even if I built the project. To solve that I selected Build->Rebuild Solution then closed and reopened the designer for Window1. What happens when you try that?

     

    You might also try just creating a new project with newly-created controls like I did. I might shed some light on your issue with others' code (those problems are always more difficult to debug).

     

    Hope this helps!

    Scott Nonnenberg

    Wednesday, September 12, 2007 4:21 PM
  • Scott,

     

    Thanks a million.  I duplicated your example and it works!!!  So the clr-namespace is not really the issue.  Like you, it took a couple of rebuilds to get it work right.  But, in my case I am very new to C#, so I count that up to my learning experience.  Unlike your experience, I did not get the squiggly lines under the clr-namespace entry this time.  But,it did take a rebuild or two to know that it was working.

     

    So, C# is OK.  Since each of the projects originally referenced went through a translation/conversion process for the 2008 level, I suspect that something in that process is not yet complete.  Because, as you pointed out, when you build it from scratch, it works.

     

    Thanks again for the info.  I am sure there will be more questions in the future.

     

    Wednesday, September 12, 2007 8:02 PM

All replies

  • Hello.

     

    Unfortunately it's hard to say if what you're experiencing is a limitation of the product, a bug in the product or a project configuration issue. Can you provide some more information about your solution? Do you have multiple projects? I notice that you mention both "Master Pages" and "clr-namespace" - as far as I understand it, one is an ASP.NET concept, and the other is a Windows Presentation Foundation concept.

     

    Is that the exact and complete text of the error you get? Sometimes "could not create instance of type" is caused because certain requirements need to be met before an instance can be created (like a public constructor with no parameters). Or your references are out of date (you need to do a complete rebuild).

     

    Thanks,

    Scott Nonnenberg

     

     

     

     

    Wednesday, September 12, 2007 1:00 AM
  • Scott,

     

    You are absolutely right.  What I wrote was gibberish.  (It seemed to make sense at the time I wrote it, but looking back on it..... well it doesn't.)

     

    I started out wanting to have a WPF window with multiple pages (with a nav bar at the top).  I was excited to find just the example I wanted at this location:  http://www.codeproject.com/WPF/WPFMasterPage.asp 

     

    I downloaded and moved the project to my project folder and tried to load it.  When I click on the Page1.xaml entry I get the following header lines:

     

    <Page x:Class="MasterPages.Page.Page1"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:m="clr-namespace:MasterPages.App_Master"

        Title="Page1"

       >

       <m:Master>

            <m:Master.Title>....

     

    At first I got an error message referring to the "clr-namespace..." line.  Now I don't get that message, but I get an error on the <m:Master .. lines.  The error message is: "Could not create an instance of type 'Master'   -- (even though the class "Master" is defined in the MasterPages.App_Master namespace).

     

    I thought there might be an issue with versions, etc. so I borrowed some similar code from my son who is a professional C# programmer.  His code with a similar "clr-namespace" reference gave me the same error message.  So, I believe it is something with the way I have my C# configured (or not configured correctly).

     

    Which leaves me wondering if I have a bad configuration, or the Express IDE just does not handle this.

     

    Any assistance you can give is greatly appreciated.

     

     

    Wednesday, September 12, 2007 2:48 AM
  • You're just trying to use a WPF UserControl in your application, so it's certainly not a limitation of C# Express. I just loaded up C# Express Beta2, created a WPF app, added a WPF UserControl to that app (right-click on project, select Add New Item, WPF User Control), then used the control in the main Window of that app (added the xmlns attribute and subsequent reference to the control manually). So it is possible - here's the XAML:

     

    <Window x:Class="WpfApplication1.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:local="clr-namespace:WpfApplication1"

    Title="Window1" Height="300" Width="300">

    <Grid>

    <local:UserControl1/>

    </Grid>

    </Window>

     

    I did run into some weirdness where the designer didn't refresh after I added the new control - it continued to complain (in the XML with blue squiggles) that it couldn't find the control even if I built the project. To solve that I selected Build->Rebuild Solution then closed and reopened the designer for Window1. What happens when you try that?

     

    You might also try just creating a new project with newly-created controls like I did. I might shed some light on your issue with others' code (those problems are always more difficult to debug).

     

    Hope this helps!

    Scott Nonnenberg

    Wednesday, September 12, 2007 4:21 PM
  • Scott,

     

    Thanks a million.  I duplicated your example and it works!!!  So the clr-namespace is not really the issue.  Like you, it took a couple of rebuilds to get it work right.  But, in my case I am very new to C#, so I count that up to my learning experience.  Unlike your experience, I did not get the squiggly lines under the clr-namespace entry this time.  But,it did take a rebuild or two to know that it was working.

     

    So, C# is OK.  Since each of the projects originally referenced went through a translation/conversion process for the 2008 level, I suspect that something in that process is not yet complete.  Because, as you pointed out, when you build it from scratch, it works.

     

    Thanks again for the info.  I am sure there will be more questions in the future.

     

    Wednesday, September 12, 2007 8:02 PM
  • One cause for "Could not create instance of type..." that bit me was that I was somehow missing the required call to InitializeComponent() in the constructor of my UserControl-derived class.  That burned some time!   (this was in VS2008 v9.0.30729,1 SP, .NET3.5 SP1)
    Thursday, June 18, 2009 10:43 PM
  • Found couple of solutions that finally works:

    1. http://www.laumania.net/post/A-possible-solution-to-the-error-e2809cXAML-Namespace-httpschemasmicrosoftcomexpressionblend2008-is-not-resolvede2809d.aspx

    2. Solution must require to have "Debug" configuration. If projects has its custom configuration, keep the default Debug configuration available, although it doesn't require.

    Tuesday, October 5, 2010 9:23 PM