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

  • SEARCH
  • Home
  • 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 7062019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:32:39+00:00 2026-05-28T04:32:39+00:00

[TestFixture] public class ExpandoToMessageConverterTests { /// <summary> /// CanConvertEvent /// </summary> [Test] public void

  • 0
[TestFixture]
public class ExpandoToMessageConverterTests
{
/// <summary>
/// CanConvertEvent
/// </summary>
[Test]
public void CanConvertEvent()
{
    dynamic expandoEvent = new ExpandoObject();
    expandoEvent.PropertyOne = "pROPERTYoNE";
    expandoEvent.PropertyTow = "pROPERTYtWO";

    XElement xEvent=ExpandoToMessageConverter.ExpandoToMessageEvent(expandoEvent);

    /*var xEvent = new XElement("event",
                                new XElement("properties",
                                            new XElement("property",
                                                        new XAttribute("name", "pROPERTYoNE"),
                                                        new XAttribute("value", "someVal")),
                                            new XElement("property",
                                                        new XAttribute("name", "pROPERTYtWO"),
                                                        new XAttribute("value", "BLAH"))));*/
    Assert.IsNotNull(xEvent);
    var properties = new List<XElement>(xEvent.Descendants("properties"));
    Assert.AreEqual(1,properties.Count);


    var value = ((IEnumerable)xEvent.XPathEvaluate("properties/property")).Cast<XElement>();
    Assert.AreEqual(2, value.Count());
}

In the code above I create the same xml in different ways (one, explicit, is commented out). The other one is using the ExpandoToMessageEvent(ExpandoObject), which returns a XElement.
Here is the mystery for me:

  • if I declare xEvent as var xEvent the CLR complains that XPathEvaluate is not defined on XElement. It is not, indeed; its an extension method.
  • the way the snippet is now (i.e. xEvent declared as XElement), it works fine.
  • if I replace the section starting with ‘dynamic’ and ending at the end of the call to my ExpandoToMessageEvent method with the section that is currently commented out CLR is happy.

Obviously, I can make it work. But the question is: why does ‘dynamic’ word throw CLR off?

I decided to check a couple more things and here is what I found: If i pass a new ExpandoObject() to the function then the type of xEvent in the “var xEvent = ExpandoToMessageConverter.ExpandoToMessageEvent(new ExpandoObject())” is determined correctly and CLR is happy. However, if I say “dynamic blah = new ExpandoObject()” and then ” var xEvent=ExpandoToMessageEvent(blah)”, the type of xEvent is not determined correctly (I guess) and CLR does not seem to consider extension methods for XElement.

  • 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-28T04:32:39+00:00Added an answer on May 28, 2026 at 4:32 am

    Overload resolution of a dynamic invocations does not consider extension methods.

    Determining what extension methods are available on a given call requires knowing what “using” directives were in force at the call site. We had no previously existing mechanism for persisting this information into the call site; we did not have the budget to design, implement, test and document a new mechanism and still ship C# 4 on time. We therefore cut that portion of the feature.

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

Sidebar

Related Questions

Check out this test: [TestFixture] public class Quick_test { [Test] public void Test() {
Here is my test: [TestFixture] public class DisplayingPageLinks { [Test] public void Can_Generate_Links_To_Other_Pages() {
Here is the unit test: [TestFixture] public class HomeControllerTests { [Test] public void Index_GET_Asks_For_Index_View()
The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test]
namespace MoqSample.Test { [TestFixture] public class GivenCustomerServiceTest { private ICustomerService customerService; private CustomerModel customer;
Here's what I have in my test so far: [TestFixture] public class IndividualMovieTests {
Using NUnit 2.5.9, the following test unexpectedly fails: [TestFixture] public class FooTest { [Test]
using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; namespace UnitTest.Model { [TestFixture] public class
I have a test method created using Selenium, something similar to this: [TestFixture] public
Is it possible to get this scenario to work ? [TestFixture] public class AutofacTests

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.