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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:13:00+00:00 2026-05-16T01:13:00+00:00

Is there any way to use the new dynamic features in the 4.0 framework

  • 0

Is there any way to use the new dynamic features in the 4.0 framework like ExpandoObject in VB.NET without setting Option Strict Off? With C#, you lose type safety only with the variables you specifically declare as dynamic. But with VB, the only way I’ve found to use these features is with the old Option Strict Off trick that’s been in VB.NET since the beginning. Without Option Strict, everything in the file is polluted with fuzzy typing like so:

Option Explicit On
Option Strict Off
Option Infer On

Partial Public Class ClassX

   Public Sub TestDynamic()
      Dim dyn As Object = New System.Dynamic.ExpandoObject()
      Dim a As String = 1 ''# Ew!
      Dim obj As Object = "999"

      dyn.Str = a   ''# a is a string, remember?  Even though it has a number
      ''# dyn.Str = 1 : Type = System.String
      Console.WriteLine("dyn.Str = {0} : Type = {1}", dyn.Str, dyn.Str.GetType().ToString())

      dyn.Num = 123
      ''# dyn.Num = 123 : Type = System.Int32
      Console.WriteLine("dyn.Num = {0} : Type = {1}", dyn.Num, dyn.Num.GetType().ToString())

      dyn.Dbl = obj / 9
      ''# dyn.Dbl = 111 : Type = System.Double
      Console.WriteLine("dyn.Dbl = {0} : Type = {1}", dyn.Dbl, dyn.Dbl.GetType().ToString())

      dyn.Obj = obj
      ''# dyn.Obj = 999 : Type = System.String
      Console.WriteLine("dyn.Obj = {0} : Type = {1}", dyn.Obj, dyn.Obj.GetType().ToString())

      dyn.Dte = #5/5/1955#
      ''# dyn.Dte = 7/7/1977 12:00:00 AM : Type = System.DateTime
      Console.WriteLine("dyn.Dte = {0} : Type = {1}", dyn.Dte, dyn.Dte.GetType().ToString())

      AmICalled(dyn.Num)
      AmICalled(dyn.Obj)
      AmICalled(dyn.Str)
      AmICalled(dyn.Dbl)

      Try
         AmICalled(dyn.Dte)
      Catch
         Console.WriteLine("Dates don't convert to ints I guess... but we don't know that 'till runtime")
      End Try

      Console.WriteLine(dyn.Num + dyn.Str) ' 124!?
      Console.WriteLine(dyn.Num & dyn.Str) ' 1231!?

   End Sub

   Private Sub AmICalled(ByVal i As Integer)
      Console.WriteLine("AmICalled was called with: " & i)
   End Sub

End Class

Is this really correct? And, if so, what’s the best way to still use things like ExpandoObject and mitigate the risk of losing all type safety? Partial classes? Or should I just not be so worried about type safety in this case?

  • 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-16T01:13:01+00:00Added an answer on May 16, 2026 at 1:13 am

    It appears you can’t without having to turn Option Strict off.
    I’ll research some more though.


    Edit


    After going through some documentation on the ExpandoObject, it appears it is used in C# for COM and Office Interop. Traditionally, in VB.NET, the Object was used for such purposes and that would require you turn off Option Strict.

    To answer your question this means that you can use dynamic types in VB.NET by using the Object type instead of the ExpandoObject [if such a type exists in VB.NET], set Option Infer On and Option Strict On or Off.
    You could also consider using partial classes to localise your non Option Strict code to particular files.

    Suggested Reading

    • Dynamic Type in C#, Equivalent in VB
    • Using Type Dynamic (C# Programming Guide)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to use server controls in ASP.NET MVC? Specifically I need
Is there any way to Use the Builtin ScrollBars that comes with each .Net
Without using dynamic SQL, and other than an If ELSE is there any way
Is there any way to use dynamic keys with the node-mongodb-native driver? By this
Is there any way to use inheritance in database (Specifically in SQL Server 2005)?
Is there any way to use a constant as a hash key? For example:
Is there any way to use C# to build a container application where each
Is there any way to use AppleScript (or something else) to query currently running
Is there any way to use Relative path when configuring subversion externals. For example
Is there any way to use ActiveRecord calculations while also acquiring relevant field names?

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.