Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Bug In VB.NET Compiler?

Bug In VB.NET Compiler?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpc++dotnet
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael Russell
    wrote on last edited by
    #1

    One of the features that I really like about Visual Basic .NET is the ability to declare ReadOnly arrays of value types. However, use of this feature can cause Visual Basic .NET to emit an invalid assembly. To demonstrate what I'm talking about, let's construct a simple lookup table. The table in question maps integers to doubles and strings, never changes, and does not have an available formula to allow calculations. Because the LUT needs to be available from launch, a ReadOnly array is created. Public Structure LUTItem Dim D As Double Dim S As String Sub New(DValue As Double, SValue As String) Me.D = DValue Me.S = SValue End Sub End Structure Public ReadOnly LUTS() As LUTItem = { _ New LUTItem(0.03,"A number"), _ New LUTItem(0.91,"Another number" } For small arrays, this works wonderfully. However, when you pass around 30,000 items in your array, two things happen: 1) Visual Studio .NET gets heinously slow after every change to the file as it recompiles the file. 2) When you build, the build is successful, but when you run, you are told that the assembly is not valid. So, my question is this: why is there a disconnect here? If this particular structure is invalid for the runtime, why does it compile without errors or warnings? If this particular structure is valid for the runtime, why does the CLR call it an invalid assembly? Note: I know that creating a massive LUT that way in the assembly is poor coding style. However, when porting software, it is often easier to do a straight port first, then enhance later. I encountered this porting a C++ library to VB.NET when I moved over a 48,000+ element array of structs used in the code that included function pointers and data to pass to the function pointers. Because it was a const array, I was trying to keep a similar access modifier in case any changes I made to the library inadvertently changed values in the array. Besides, who wants to create 48,000+ delegates while loading a file?

    D 1 Reply Last reply
    0
    • M Michael Russell

      One of the features that I really like about Visual Basic .NET is the ability to declare ReadOnly arrays of value types. However, use of this feature can cause Visual Basic .NET to emit an invalid assembly. To demonstrate what I'm talking about, let's construct a simple lookup table. The table in question maps integers to doubles and strings, never changes, and does not have an available formula to allow calculations. Because the LUT needs to be available from launch, a ReadOnly array is created. Public Structure LUTItem Dim D As Double Dim S As String Sub New(DValue As Double, SValue As String) Me.D = DValue Me.S = SValue End Sub End Structure Public ReadOnly LUTS() As LUTItem = { _ New LUTItem(0.03,"A number"), _ New LUTItem(0.91,"Another number" } For small arrays, this works wonderfully. However, when you pass around 30,000 items in your array, two things happen: 1) Visual Studio .NET gets heinously slow after every change to the file as it recompiles the file. 2) When you build, the build is successful, but when you run, you are told that the assembly is not valid. So, my question is this: why is there a disconnect here? If this particular structure is invalid for the runtime, why does it compile without errors or warnings? If this particular structure is valid for the runtime, why does the CLR call it an invalid assembly? Note: I know that creating a massive LUT that way in the assembly is poor coding style. However, when porting software, it is often easier to do a straight port first, then enhance later. I encountered this porting a C++ library to VB.NET when I moved over a 48,000+ element array of structs used in the code that included function pointers and data to pass to the function pointers. Because it was a const array, I was trying to keep a similar access modifier in case any changes I made to the library inadvertently changed values in the array. Besides, who wants to create 48,000+ delegates while loading a file?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      If all you have in this table is key and value pairs, why not implement it as a Dictionary using the DictionaryBase class? You can make your Dictionary ReadOnly and provide Insert Validation. RageInTheMachine9532

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        If all you have in this table is key and value pairs, why not implement it as a Dictionary using the DictionaryBase class? You can make your Dictionary ReadOnly and provide Insert Validation. RageInTheMachine9532

        M Offline
        M Offline
        Michael Russell
        wrote on last edited by
        #3

        The example was a simplified version of the actual port work. The example has problems after 30,000 entires, as does the actual port work, which has 11 seperate properties, including three delegates. As for your recommendation, I do agree. That would be preferred were it possible. However, there are strengths to using a ReadOnly array, namely compile-time array write checking rather than runtime checking, increased performance, and strong typing without a wrapper class. But the main issue here is which is wrong: the compiler compiling code that should not run, or the CLR crashing on code that should?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups