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. Web Development
  3. ASP.NET
  4. Reflection

Reflection

Scheduled Pinned Locked Moved ASP.NET
xmlhelpquestionworkspace
3 Posts 3 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
    Monin D
    wrote on last edited by
    #1

    I have a following structure

    App_Code
    MyClass.cs [Company.MyNameSpace.MyClass]
    Bin
    MyLib.dll [Company.MyLibNameSpace.LibraryClass]

    From Company.MyLibNameSpace.LibraryClass I need to create an instance of Company.MyNameSpace.MyClass, but I don't know Class name until execution (it comes from XML configuration), so I use Reflection for it:

    Type type = Type.GetType("Company.MyNameSpace.MyClass")

    The problem is, that when I load a Type from DLL, it doesn't work (type == null), when I do the same from another .cs file in App_Code folder, everything works fine. Is there any work-around to this problem?

    G A 2 Replies Last reply
    0
    • M Monin D

      I have a following structure

      App_Code
      MyClass.cs [Company.MyNameSpace.MyClass]
      Bin
      MyLib.dll [Company.MyLibNameSpace.LibraryClass]

      From Company.MyLibNameSpace.LibraryClass I need to create an instance of Company.MyNameSpace.MyClass, but I don't know Class name until execution (it comes from XML configuration), so I use Reflection for it:

      Type type = Type.GetType("Company.MyNameSpace.MyClass")

      The problem is, that when I load a Type from DLL, it doesn't work (type == null), when I do the same from another .cs file in App_Code folder, everything works fine. Is there any work-around to this problem?

      G Offline
      G Offline
      Gamzun
      wrote on last edited by
      #2

      Are you sure you're loading it correctly?

      Please don't forget to mark 'Good Answer', if you find it really a good one! Kashif

      1 Reply Last reply
      0
      • M Monin D

        I have a following structure

        App_Code
        MyClass.cs [Company.MyNameSpace.MyClass]
        Bin
        MyLib.dll [Company.MyLibNameSpace.LibraryClass]

        From Company.MyLibNameSpace.LibraryClass I need to create an instance of Company.MyNameSpace.MyClass, but I don't know Class name until execution (it comes from XML configuration), so I use Reflection for it:

        Type type = Type.GetType("Company.MyNameSpace.MyClass")

        The problem is, that when I load a Type from DLL, it doesn't work (type == null), when I do the same from another .cs file in App_Code folder, everything works fine. Is there any work-around to this problem?

        A Offline
        A Offline
        Abhishek Sur
        wrote on last edited by
        #3

        As you dont have reference to Company.MyNameSpace.MyClass, you need to manually read the assembly using Reflection and then using Activator.CreateInstance you create the instance of the class. For instance : Assembly assem = Assembly.Load("\folder\MyLib.dll"); object thisObj = assem.CreateInstance("Company.MyNameSpace.MyClass"); For further reading use http://www.c-sharpcorner.com/UploadFile/samhaidar/LateBindingWithReflection09122005053810AM/LateBindingWithReflection.aspx[^]:rose:

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Simplify Code Using NDepend
        Basics of Bing Search API using .NET
        Microsoft Bing MAP using Javascript

        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