View Single Post
Old 12-13-2006   #1 (permalink)
Keith Patrick


 
 

x:Static with constants won't work (weird error + Class not found)

I am trying to use a constant in a resource defined in my App.xaml.
Everything's fine when it's hardcoded, but when I put in an {x:Static
c:Constants.MyConst}, I get a couple of errors. The first one is the
weirdest. As soon as I make the aforementioned change (this is all in
Visual Crash 2005), I get a dialog about App.xaml not belonging to the
project I'm debugging, so it can't enter break mode, "Usually, this
condition occurs when the project was not rebuilt prior to starting the
debugging session (not true), when the assembly file for the project is out
of date (don't believe this to be true, although with 2005's f'ed up
caching, who knows?), etc." Selecting OK gives me an exception: Type
reference cannot find public type named 'Constants'. Error at Line 8
Position 30. I don't see what I'm doing differently from how the
documentation describes, as my namespace appears to be fine, but it's as if
the runtime doesn't even consider the namespace

Here's my markup:
<Application x:Class="MyNS.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="MyNS"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<XmlDataProvider x:Key="{x:Static Member=c:Constants.MyConst}"
Source="pack://siteoforigin:,,,/Data/Objectives.xml"/>
....

And the class is
namespace MyNS
{
#region Referenced Namespaces
using System;
#endregion // Referenced Namespaces

public static class Constants
{
public const String MyConst = "At least this error doesn't make
VS.Net actually crash";
}
}


My System SpecsSystem Spec