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 8409733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:59:30+00:00 2026-06-09T23:59:30+00:00

I added an Anonymous type to my project: ‘Put the courses from the XML

  • 0

I added an Anonymous type to my project:

'Put the courses from the XML file in an Anonymous Type
Dim courses = From myCourse In xDoc.Descendants("Course")
              Select New With
                  {
                      .StateCode = myCourse.Element("StateCode").Value, _
                      .Description = myCourse.Element("Description").Value, _
                      .ShortName = myCourse.Element("ShortName").Value, _
                      .LongName = myCourse.Element("LongName").Value, _
                      .Type = myCourse.Element("Type").Value, _
                      .CipCode = CType(myCourse.Element("CIPCode"), String) _
                }

For Each course In courses
    If Not UpdateSDECourseCode(acadYear, course.StateCode, course.Description, course.Type, course.ShortName, course.LongName, course.CipCode) Then errors.Add(String.Format("Cannot import State Course Number {0} with Year {1} ", course.StateCode, acadYear))
Next

After doing so, a Unit Test failed:

Public Function GetAreaTypeList() As List(Of Type)
    Dim types As New List(Of Type)
    Dim asmPath As String = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "My.Stuff.dll")

    For Each t As Type In Reflection.Assembly.LoadFrom(asmPath).GetTypes()
        If t.Namespace.StartsWith("My.Stuff.BatchUpdater") Then
            If t.BaseType Is GetType(My.Stuff.BatchUpdater.Area) Then
                types.Add(t)
            End If
        End If
    Next

    Return types
End Function

It fails because a new type has been added to the project (VB$AnonymousType_0`6) and it does not have a property called Namespace.

I fixed by making the following change to the IF Statement:

If Not t.Namespace Is Nothing AndAlso t.Namespace.StartsWith("My.Stuff.BatchUpdater") Then

Since I don’t fully understand what’s happening, I feel leery about my code change.

Why is the Namespace Nothing for the Anonymous type?

Would you fix your Unit Test in the same fashion? Or should it be something more specific (e.g. If Not t.Names = “VB$AnonymousType_0`6”)


UPDATE

decyclone gave me the info I needed to create a better test:

For Each t As Type In Reflection.Assembly.LoadFrom(asmPath).GetTypes()
    'Ignore CompilerGeneratedAttributes (e.g. Anonymous Types)
    Dim isCompilerGeneratedAttribute = t.GetCustomAttributes(False).Contains(New System.Runtime.CompilerServices.CompilerGeneratedAttribute())

    If Not isCompilerGeneratedAttribute AndAlso t.Namespace.StartsWith("My.Stuff.BatchUpdater") Then
         '...Do some things here
    End If
Next

Honestly, it could be improved more with a LINQ query, but this suits me.

  • 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-06-09T23:59:31+00:00Added an answer on June 9, 2026 at 11:59 pm

    Anonymous methods and types are decorated with CompilerGeneratedAttribute. You can check for their existance to identify an anonymous type.

    var anonymous = new { value = 1 };
    
    Type anonymousType = anonymous.GetType();
    var attributes = anonymousType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false);
    
    if (attributes.Any())
    {
        // Anonymous
    }
    

    You can filter these out in your test.

    It is also possible to mark a user defined type with CompilerGeneratedAttribute. So maybe you can combine it with checking if Namespace is null or not

    var anonymous = new { value = 1 };
    
    Type anonymousType = anonymous.GetType();
    var attributes = anonymousType.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false);
    
    if (attributes.Any() && anonymousType.Namespace == null)
    {
        // Anonymous
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to retrieve named members from an anonymous type. Is
I got a SharePoint Project which already works with anonymous Access. Now I added
I have added Jacson libs to my android project and now I am getting
With CCK, I've added a field to the basic Page node type called Resource
I have added the following configuration section to my web.config file <security> <authentication> <anonymousAuthentication
I am getting compiler error: cannot cast expression of type 'System.Xml.Linq.XElement to type AutomationStatusType
I have a Linq query that returns an anonymous type, which I then use
I added ?callback=? to the url in the get request with an anonymous function,
I am trying to create an anonymous function but need to access variables from
I added following at line 42 of proto.h: typedef boost::make_unsigned<off_t>::type uoff_t; And now I

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.