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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Type.GetType()

Type.GetType()

Scheduled Pinned Locked Moved ASP.NET
question
7 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
    Mircea Grelus
    wrote on last edited by
    #1

    I'm trying to instantiate a class by name. The class is in my projects namespace and located in a file in the App_Code folder. Basically I am calling : Type tip = Type.GetType("PortalModuleControl"); where PortalModuleControl is the mentioned class; But tip returns null. Isn't Type.GetType supposed to look for the definition of the class in the current assembly?

    regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

    F 1 Reply Last reply
    0
    • M Mircea Grelus

      I'm trying to instantiate a class by name. The class is in my projects namespace and located in a file in the App_Code folder. Basically I am calling : Type tip = Type.GetType("PortalModuleControl"); where PortalModuleControl is the mentioned class; But tip returns null. Isn't Type.GetType supposed to look for the definition of the class in the current assembly?

      regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

      F Offline
      F Offline
      Felipe Dalorzo
      wrote on last edited by
      #2

      Yes what you are doing is not right... Here is a the rith way: Type type = Type.GetType("MyNameSpace.TheWholeThing.MyClassName, MyNameSpace"); MyAssemblyName issually is the same as the namespace, for instance but not always: namespace TQU.Demo{ public class Test2{ } } namespace TestingTypes { class Class1 { [STAThread] static void Main(string[] args) { Type type = Type.GetType("TQU.Demo.Test2, TestingTypes"); } } } Greetings ;P

      FDM

      M 1 Reply Last reply
      0
      • F Felipe Dalorzo

        Yes what you are doing is not right... Here is a the rith way: Type type = Type.GetType("MyNameSpace.TheWholeThing.MyClassName, MyNameSpace"); MyAssemblyName issually is the same as the namespace, for instance but not always: namespace TQU.Demo{ public class Test2{ } } namespace TestingTypes { class Class1 { [STAThread] static void Main(string[] args) { Type type = Type.GetType("TQU.Demo.Test2, TestingTypes"); } } } Greetings ;P

        FDM

        M Offline
        M Offline
        Mircea Grelus
        wrote on last edited by
        #3

        Type type = Type.GetType("myNameSpace.PortalModuleControl, myNameSpace"); doesn't work either. I have only one namespace in my application. I'm dealing with an ASP.NET application. Are there some restrictions regarding this?

        regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

        F 1 Reply Last reply
        0
        • M Mircea Grelus

          Type type = Type.GetType("myNameSpace.PortalModuleControl, myNameSpace"); doesn't work either. I have only one namespace in my application. I'm dealing with an ASP.NET application. Are there some restrictions regarding this?

          regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

          F Offline
          F Offline
          Felipe Dalorzo
          wrote on last edited by
          #4

          Type type = Type.GetType("myNameSpace.PortalModuleControl, MyAssemblyName"); Can you tell me if your namespace is the same as your assembly name. What's your assembly name?

          M 1 Reply Last reply
          0
          • F Felipe Dalorzo

            Type type = Type.GetType("myNameSpace.PortalModuleControl, MyAssemblyName"); Can you tell me if your namespace is the same as your assembly name. What's your assembly name?

            M Offline
            M Offline
            Mircea Grelus
            wrote on last edited by
            #5

            Hmm, I'm guessing it is. My Asp.Net application is running using the ASP.NET Development server which from my understanding acts like IIS and precompiles the code while running. I tried deploying the application but there's no DLL in the bin folder :confused: Anyway, from my understanding the assembly doesn't need to be specified when you use Type.GetType. Only when you use Assembly.GetType Am I wrong?

            regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

            F 1 Reply Last reply
            0
            • M Mircea Grelus

              Hmm, I'm guessing it is. My Asp.Net application is running using the ASP.NET Development server which from my understanding acts like IIS and precompiles the code while running. I tried deploying the application but there's no DLL in the bin folder :confused: Anyway, from my understanding the assembly doesn't need to be specified when you use Type.GetType. Only when you use Assembly.GetType Am I wrong?

              regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

              F Offline
              F Offline
              Felipe Dalorzo
              wrote on last edited by
              #6

              Buddy u got all wrong. If you don't see the dll in your bin directory it is because either you did not compile it or you are getting a compilation error. ASP.NET does not compile the ASP.NET code in runtime, .NET compiles IL in runtime. If you want to see the your assembly name right click the project and click properties, there are some tabs there one of them will have the assembly name. Greetings :^)

              M 1 Reply Last reply
              0
              • F Felipe Dalorzo

                Buddy u got all wrong. If you don't see the dll in your bin directory it is because either you did not compile it or you are getting a compilation error. ASP.NET does not compile the ASP.NET code in runtime, .NET compiles IL in runtime. If you want to see the your assembly name right click the project and click properties, there are some tabs there one of them will have the assembly name. Greetings :^)

                M Offline
                M Offline
                Mircea Grelus
                wrote on last edited by
                #7

                Felipe Dalorzo wrote:

                If you don't see the dll in your bin directory it is because either you did not compile it or you are getting a compilation error.

                I wish that was it. Unfortunately something goes wrong. Meaning the project builds, it runs, but when I publish it, the directory that I choose to publish to is empty. I have tried all options in the publish dialog and the result is the same. Aparently others are experiencing this, too. No I just need to have a solution that aparently others didn't find:doh:

                Felipe Dalorzo wrote:

                ASP.NET does not compile the ASP.NET code in runtime

                The App_Code folder and its special status in a web application allows you to store classes that will automatically be compiled at run time.

                regards, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.

                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