Skip to content

Debugging XAML Errors at Runtime

February 10, 2007

Reposting info that I posted on a forum thread.  I’ve reordered and rewritten the content a bit.

When I have a mistake like this in my XAML:

<Grid Background="Greeeen">

Sometimes XAML intellisense will help you catch this kind of error…but not always. The XAML markup compiler doesn’t currently catch errors like this. So you end up with this "Greeen" compiled into the assembly you are running (inside of the BAML binary stream.)

Debugging with VS 2005 at runtime, you will see errors like this (bad error message and pointing to the wrong location):

Cannot create instance of ‘Window1’ defined in assembly ‘UsingWpfUtilities, Version=1.0.2593.18928, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation.  Error in markup file ‘UsingWpfUtilities;component/Window1.xaml’ Line 1 Position 9.

We are working to improve this experience in VS "Orcas", but the best way to deal with this under VS 2005 is to:

Choose Debug\Exceptions\Add:

ComboBox: Common Lanaguage Runtime Exceptions
TextBox: System.Windows.Markup.XamlParseException

Check the "Thrown" box for that newly added Exception (S.W.M.XPE)

Debugging the app (F5) will now catch the XamlParseException and give you the following message:

Cannot convert the value in attribute ‘Background’ to object of type ‘System.Windows.Media.Brush’. Token is not valid.  Error at object ‘System.Windows.Controls.Grid’ in markup file ‘UsingWpfUtilities;component/window1.xaml’ Line 10 Position 6.

In builds of VS "Orcas" that aren’t too far away, we’ll do a few things to make this better:

1) The designer will get better, so that you’ll need to spend less time typing XAML by hand.
2) The XAML editor will no longer be based on XSD, so that we’ll be able to greatly improve the intellisense experience…red squiggles will really mean there is a problem!
3) At runtime, we’ll try to relate the runtime exception back directly to the right place in the XAML.

Until then…sorry.

From → XAML (non-UI)

23 Comments
  1. Unknown permalink

    That\’ll help me a lot, thanks for that information!

    Hate to wait for Orcas…😀

  2. Dan permalink

    I have followed these instructions but have no change in the exception info I am receiving.

  3. Brennon Williams permalink

    Rob… this little piece of information has just helped me solve an issue Ive had for 3 days…. all because of a color resource being applied to a gradient stop…. I say thanks for the tip, its most appreciated, but I also ask to please ensure that debugging takes a higher priority within VS… now you we have designers using things like Blend for WPF (Which is where this error occured) they have very little chance of ever fixing issues like the one I had when most dont even know where to start looking because its a compiler issue.
     
    Thanks again for the tip, without it, I would have had to start removing stuff until I found the issue..

  4. Unknown permalink

    wow gold!All wow gold US Server 24.99$/1000G on sell! Cheap wow gold,wow gold,wow gold,Buy Cheapest/Safe/Fast WoW US EU wow gold Power leveling wow gold from the time you wWorld of Warcraft gold ordered!

    wow power leveling wow power leveling power leveling wow power leveling wow powerleveling wow power levelingcheap wow power leveling wow power leveling buy wow power leveling wow power leveling buy power leveling wow power leveling cheap power leveling wow power leveling wow power leveling wow power leveling wow powerleveling wow power leveling power leveling wow power leveling wow powerleveling wow power leveling buy rolex cheap rolex wow gold wow gold wow gold wow gold -144858892757981

  5. Unknown permalink

    不動産投資 システム開発 札幌 不動産 仙台 不動産 大阪 不動産 横浜 不動産 名古屋 不動産 福岡 不動産 京都 不動産 埼玉 不動産 千葉 不動産 静岡 不動産 神戸 不動産 浜松 不動産 堺市 不動産 川崎市 不動産 相模原市 不動産 姫路 不動産 岡山 不動産 明石 不動産 鹿児島 不動産 北九州市 不動産 熊本 不動産 インテリアコーディネータ リフォーム 東京 リフォーム 大阪 不動産 査定 不動産 買取 不動産 売買 不動産 鑑定 不動産 売却 サイトを検索すると会社があったよくみると賃貸 住宅も収益物件も不動産 賃貸も賃貸マンションも新築マンションもしっかりカバーしてありすごく充実したさいとでもちろん投資を目的の方やリフォームをしたい人もすごく参考になるだう。ところで今、SEO対策などいまはやっているがホームページ制作会社にいらいしてもうまくはいかないようだ。最近私は、資産運用にこっていて税金対策にインテリアを集めている。もちろんファッションにこだわりブランド品や下着にはこだわりがある。 化粧品も高価なものがよく家具も最高級しか買わない、先日海外旅行にいってきてお土産に外車と結婚指輪と高級時計をかったが、日本でしらべたら通販ですごく安く売っていた。
    今、会社の寮で賃貸を探してまして全部で12都市で社員が住みます場所は、福岡 賃貸,広島 賃貸,川崎 賃貸,神戸 賃貸,京都 賃貸,名古屋 賃貸,大阪 賃貸,埼玉 賃貸,札幌 賃貸,仙台 賃貸,千葉 賃貸,横浜 賃貸の政令指定都市が対象です不動産と賃貸と投資とは収益物件探し新築の住宅はアパートとマンションの土地から不動産投資

  6. Unknown permalink


    信是個富有挑戰的工作,忙碌、刺激、激情。最后的結局總是有人哭,有人笑。在徵信社工作的幾年時間里,我感悟到很多生活的無奈與殘酷。閑暇時我去中古车市
    场,感覺工作太緊張,放松一下而已,不是純粹的為了淘二手车。私家偵探也就是徵信工作人員似乎是個很酷的詞,但是如果誰需要私家偵探來幫忙的話,他(她)
    的婚姻也許已經亮起了紅燈。每天陪著星際客戶喝著咖啡,似乎是一件很爽的事,可是她們的眼淚比咖啡要苦的多。常常聽他們說嘈雜的燈光音響麻痹著他們的神
    經,讓他們過著醉生夢死的生活。其實,誰不渴望幸福美滿的愛情。沒有團體制服不了那些玩弄生活、玩弄感情的人,于是,徵信社應運而生。這不知道是人們的福
    音還是不幸,希望天下的每一個人都歡樂著、幸福著。坐月子是女人一生的大事,女人可以为了襁褓中的婴儿放弃一直引用的红酒而吃月子餐,这时候的女人是幸福
    而伟大的。有人歡喜有人優,有人狂笑有人大哭,我不想看到女人太多的眼淚,辭職后,我做了一位安靜、平和的室內設計師。虽然上下班没有了车接车送,但我租
    车怡然自得。偶爾和Fake
    Rolex Watch, Breitling
    Replica Watch, Best
    replica watches, Omega
    Replica Watches ecosway的朋友小聚,很愜意

  7. Unknown permalink

    Welcome to enter (wow gold) and (wow power leveling) trading site, (wow gold) are cheap, (wow power leveling) credibility Very good! Quickly into the next single! Key words directly to the website click on transactions! -144245389788040

  8. Unknown permalink

    Amberdigital Branch,Southern Stars Enterprises Co is specializing in the development and manufacturing of advertisement screens, LCD digital signage and LCD signages. Established in 1996, we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

    amberdigital Contact Us
    Southern Stars Enterprises Co (Hong Kong Office)
    Add:3 Fl, No.2, Lane 2, Kam Tsin Tsuen, Sheung Shui, Hong Kong
    Tel:+852 2681 4099
    Fax:+852 2681 4586
    Southern Stars Enterprises Co (Shenzhen Office)
    Add:DE, 16/F, Building 2, Nanguo Tower, Sungang Road, Shenzhen, China
    Tel:+86 755 2592 9100
    Fax:+86 755 2592 7171
    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[aicagbfibefiih]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: