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. C#
  4. cannot use instance of Assembly - compiler bug?

cannot use instance of Assembly - compiler bug?

Scheduled Pinned Locked Moved C#
helpvisual-studiocsharpquestion
10 Posts 4 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.
  • R Offline
    R Offline
    Rey9999
    wrote on last edited by
    #1

    Hello Everyone, I am trying to get a Type contained into a *.dll file, by means of System.Reflection. After a long and painful Googling journey, I could see that the standard procedure to do this is:

    Assembly theAssembly;
    theAssembly = Assembly.LoadFrom("TheDll.dll");
    Type theType = theAssembly.GetType("TheType");
    // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

    I don't know if there's something wrong with my VS, my c# compiler or what... but this will NOT compile! First thing first, after I've declared theAssembly, I cannot access to its methods or properties through Intellisense. If I "force" the above piece of code, I get the Invalid token '=' in class, struct, or interface member declaration error on the '=' in the second line. Am I doing something wrong? Any help would be much appreciated. Regards, Rey9999

    ~~~ From Milano to The Hague, easy as it goes ~~~

    S C 2 Replies Last reply
    0
    • R Rey9999

      Hello Everyone, I am trying to get a Type contained into a *.dll file, by means of System.Reflection. After a long and painful Googling journey, I could see that the standard procedure to do this is:

      Assembly theAssembly;
      theAssembly = Assembly.LoadFrom("TheDll.dll");
      Type theType = theAssembly.GetType("TheType");
      // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

      I don't know if there's something wrong with my VS, my c# compiler or what... but this will NOT compile! First thing first, after I've declared theAssembly, I cannot access to its methods or properties through Intellisense. If I "force" the above piece of code, I get the Invalid token '=' in class, struct, or interface member declaration error on the '=' in the second line. Am I doing something wrong? Any help would be much appreciated. Regards, Rey9999

      ~~~ From Milano to The Hague, easy as it goes ~~~

      S Offline
      S Offline
      Simon P Stevens
      wrote on last edited by
      #2

      Code compiles fine for me. Post the code for the whole class. I suspect you're missing a close brace somewhere at the bottom.

      Simon

      1 Reply Last reply
      0
      • R Rey9999

        Hello Everyone, I am trying to get a Type contained into a *.dll file, by means of System.Reflection. After a long and painful Googling journey, I could see that the standard procedure to do this is:

        Assembly theAssembly;
        theAssembly = Assembly.LoadFrom("TheDll.dll");
        Type theType = theAssembly.GetType("TheType");
        // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

        I don't know if there's something wrong with my VS, my c# compiler or what... but this will NOT compile! First thing first, after I've declared theAssembly, I cannot access to its methods or properties through Intellisense. If I "force" the above piece of code, I get the Invalid token '=' in class, struct, or interface member declaration error on the '=' in the second line. Am I doing something wrong? Any help would be much appreciated. Regards, Rey9999

        ~~~ From Milano to The Hague, easy as it goes ~~~

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I'd say you're missing a using System.Reflection at the top of this file.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        R 1 Reply Last reply
        0
        • C Christian Graus

          I'd say you're missing a using System.Reflection at the top of this file.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          R Offline
          R Offline
          Rey9999
          wrote on last edited by
          #4

          Hi, thanks for the quick reply. @Christian: I imported System.reflection, just did not copy here the whole code. @Simon: I do not think it's something about braces, because if i do this:

          Assembly theAssembly;
          theAssembly = Assembly.LoadFrom("TheDll.dll");
          Type theType = theAssembly.GetType("TheType");
          // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

          I get the error, but if I do this:

          Type theType = Assembly.LoadFrom("TheDll.dll").GetTypes()[0]

          everything runs fine! and I did not change anything in the rest of the class. Any thought on this?

          C S 2 Replies Last reply
          0
          • R Rey9999

            Hi, thanks for the quick reply. @Christian: I imported System.reflection, just did not copy here the whole code. @Simon: I do not think it's something about braces, because if i do this:

            Assembly theAssembly;
            theAssembly = Assembly.LoadFrom("TheDll.dll");
            Type theType = theAssembly.GetType("TheType");
            // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

            I get the error, but if I do this:

            Type theType = Assembly.LoadFrom("TheDll.dll").GetTypes()[0]

            everything runs fine! and I did not change anything in the rest of the class. Any thought on this?

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            OK, I added the using statement and copied your code, it compiles just fine.

            Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            R 1 Reply Last reply
            0
            • R Rey9999

              Hi, thanks for the quick reply. @Christian: I imported System.reflection, just did not copy here the whole code. @Simon: I do not think it's something about braces, because if i do this:

              Assembly theAssembly;
              theAssembly = Assembly.LoadFrom("TheDll.dll");
              Type theType = theAssembly.GetType("TheType");
              // or: Type theType = theAssembly.GetTypes()[0] as I know that there will surely be just one Type in the namespace

              I get the error, but if I do this:

              Type theType = Assembly.LoadFrom("TheDll.dll").GetTypes()[0]

              everything runs fine! and I did not change anything in the rest of the class. Any thought on this?

              S Offline
              S Offline
              Simon P Stevens
              wrote on last edited by
              #6

              This is a compiler error yeah? post the code for the whole class, I'm sure you're missing something. maybe like a semi colon. You haven't got one at the end of your commented out line, so maybe you've got an extra on on a line below, so when you change the comments the semi colons are correct. All the lines you've provided compile fine for me (I just had to add the semi colon to get the commented out line to compile).

              Simon

              T 1 Reply Last reply
              0
              • C Christian Graus

                OK, I added the using statement and copied your code, it compiles just fine.

                Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                R Offline
                R Offline
                Rey9999
                wrote on last edited by
                #7

                Jesus H. Christ, I was doing the dumbest and biggest mistake - the one you learn NOT to do on Programmers kindergarten, Day One. I was trying to access the assembly outside of a method. Thanks all the same. I just need to sleep more than 5 hours a night...

                ~~~ From Milano to The Hague, easy as it goes ~~~

                1 Reply Last reply
                0
                • S Simon P Stevens

                  This is a compiler error yeah? post the code for the whole class, I'm sure you're missing something. maybe like a semi colon. You haven't got one at the end of your commented out line, so maybe you've got an extra on on a line below, so when you change the comments the semi colons are correct. All the lines you've provided compile fine for me (I just had to add the semi colon to get the commented out line to compile).

                  Simon

                  T Offline
                  T Offline
                  tano gae
                  wrote on last edited by
                  #8

                  Are you sure you write your code in the right place?

                  R 1 Reply Last reply
                  0
                  • T tano gae

                    Are you sure you write your code in the right place?

                    R Offline
                    R Offline
                    Rey9999
                    wrote on last edited by
                    #9

                    :) :) this one above is my co-worker, sitting in front of me, I just told him I found the error - he's trying to act big ;P

                    ~~~ From Milano to The Hague, easy as it goes ~~~

                    S 1 Reply Last reply
                    0
                    • R Rey9999

                      :) :) this one above is my co-worker, sitting in front of me, I just told him I found the error - he's trying to act big ;P

                      ~~~ From Milano to The Hague, easy as it goes ~~~

                      S Offline
                      S Offline
                      Simon P Stevens
                      wrote on last edited by
                      #10

                      Nice one. we all make simple mistakes from time to time.

                      Simon

                      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