Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4540166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:02:55+00:00 2026-05-21T15:02:55+00:00

I see strange behavior. I have a strong feeling that it is a bug

  • 0

I see strange behavior. I have a strong feeling that it is a bug in .net toolchain.

Steps to reproduce:

  1. Create WPF application.
  2. Create Class Library in that solution.
  3. Define some public class (can be empty) in Class Library.
  4. Define some class in WPF application with attached property and Window as target class.
  5. Attach it to Window and provide value

And you get error:

The object ‘Window’ already has a
child and cannot add ”. ‘Window’ can
accept only one child.

If you change structure so that class with attached property and value class in same assembly (can be either Class Library or Wpf Application) it works fine.

Also it works fine if you put the code after content. This gives error:

<Window x:Class="WpfApplication9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:ClassLibrary1;assembly=ClassLibrary1"
        xmlns:my2="clr-namespace:ClassLibrary1"
        Title="MainWindow" Height="350" Width="525">

    <my2:Property.MyProperty>
        <my:ValueClass />
    </my2:Property.MyProperty>

    <Grid>

    </Grid>
</Window>

This does not:

<Grid>

</Grid>    

<my2:Property.MyProperty>
    <my:ValueClass />
</my2:Property.MyProperty>

Any ideas?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:02:55+00:00Added an answer on May 21, 2026 at 3:02 pm

    This is caused by the self-referential way that XAML is compiled. Although you have a namespace reference to the assembly containing the attached property, the application assembly, that very assembly is in fact in the process of being compiled at the time you need the XAML compiler to decide that the element syntax refers to an attached property and not an ordinary element.

    As you have discovered, putting the attached property after the content is enough of a hint to get it to make the right choice even with incomplete information. On the other hand, knowing that this is the problem, you can also simply put the attached property into an external assembly, for example into the control library, and this will also avoid the chicken-and-the-egg problem.

    In a perfect world the C# compiler and the XAML compiler would be fully integrated with each other and this problem would go away but until then we’ll have to use workarounds.

    Edit:

    Another try to explain this because it is a little complicated.

    When you compile your application assembly, it contains both C# and XAML. In the sample code above the XAML refers to an attached property defined in the C# code of the same assembly. So the XAML compiler needs to have a compiled version of your application assembly in order to know that Property.MyProperty is an attached property. But the C# compiler can’t compile your application assembly yet because the XAML hasn’t been compiled. This is the chicken-and-the-egg problem: the C# and XAML both depend on each other.

    Something has got to give and the XAML compiler goes ahead and tries to compile your application’s XAML files with incomplete information, even though the application assembly hasn’t been compiled yet. In the course of doing this it can make mistakes like not detecting attached properties defined in the same assembly. Why does it work sometimes? We can note that they have gone to some effort to handle some common cases so it does appear to work most of the time but nevertheless it does not work all of the time as you have discovered.

    The easiest solution is to move your attached property into an external assembly. Attached properties like controls are generally associated with libraries anyway so the problem doesn’t usually arise.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange (don't ask) need to see a few examples of a
I have this strange issue with my web app. You see, I'm using jQuery
(see here for the problem I'm trying to solve) How do you get hibernate
See title. By lightweight markup I mean something like markdown or wikitext.
See title: what does it mean for a C++ function to be inline?
See code: var file1 = 50.xsl; var file2 = 30.doc; getFileExtension(file1); //returns xsl getFileExtension(file2);
See the question. I want to see the methods and classes offered by a
See: Understanding Pointers In many C flavoured languages, and some older languages like Fortran,
See also How does a WCF server inform a WCF client about changes? (Better
(See related question: How do I report an error midway through a chunked http

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.