Gettype() returning a null

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi,

I have an .aspx page that needs to instantiate an object whose type in
not known until runtime. The definition of said object resides in
/App_code/CMS.cs

CMS.cs
==================
namespace CMS{
public interface IWindmill{
string emit
{get;}
}

public class MyObject : IWindmill{
string html;

public MyObject(){
html = "Hello World"
}

public string emit{
get { return html; }
}
}

In my webpage, I am trying to instantiate myObject dynamically, like
so:

Default.aspx.cs
============
protected void Page_Load(object sender, EventArgs e){
Type t = Type.GetType("CMS.MyObject"); //This object will vary and
won't be determined until runtime
CMS.IWindmill myObj = (CMS.IWindmill)Activator.CreateInstance(t);

MethodInfo m = myObj.GetType().GetMethod("get_emit");
if (m != null){
string s = (string)m.Invoke(myObj, null);
Response.Write(s);
}
}

My Type t will return null unless I include the CMS namespace in the
Default.aspx.cs file. Is there a way for me to return the proper value
if the object is defined in an external file? I understand I could
package the CMS namespace in an assembly and reference it through its
qualified name, but is there an easier and more direct way to get the
type in an external .cs file?

Regards,

Chris

.



Relevant Pages

  • Re: ProgID in .NET?
    ... The ProgID has the form Project.ClassName.Version. ... version it is possible to instantiate COM objects from different versions ... When a class from a .NET assembly is instantiated its namespace and class ... The nice part about COM is that you can choose as a developer if you want to use a specific version of a COM object or not without the vendor of the DLL facing the problem we ran now into: If we don't change the namespace you can't use different versions in the same process. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: using setAttribute or set attribute directly
    ... suggest how it could be applicable to namespaces in HTML? ... Because W3C on second thought said that "HTML namespace no", ... which is one reason why XHTML became necessary. ... why did you decide that the posted code is HTML and not ...
    (comp.lang.javascript)
  • Re: using setAttribute or set attribute directly
    ... Terms: namespace http://www.w3.org/TR/REC-html40 ... into quotes, use explisit site search ... namespaces in HTML. ... An XML declaration is not required in all XML documents; ...
    (comp.lang.javascript)
  • Re: Can we create an_object = object() and add attribute like for a class?
    ... Is there any reason that under Python you cannot instantiate the object ... which may make little sense for a namespace). ...
    (comp.lang.python)
  • Re: Moving Code Breaks Namespace
    ... ..aspx as inserting code blocks between HTML tags... ... 'The type or namespace name 'details' could not be found (are you ... This was the first time in the project I needed tags, ...
    (microsoft.public.dotnet.languages.csharp)