Yeah you are right, your type CreareTransform does fulfill that criteria,
but what I was saying was that the type that you were attempting to create
at that point (which was not the one you created) didn't have a default
constructor. See, when you execute a Assembly.GetTyp es() it returns all the
types defined in that assembly, inculding interfaces and enums etc. You code
is iterating through this list impartially and attempting to create
instances to those types.
To illustrare try this out.
/* UNTESTED CODE BLOCK */
....
Assembly asm = Assembly.LoadFr om ( fileName );
Type[] asmTypes = asm.GetTypes ( );
foreach ( Type t in asmTypes )
Console.WriteLi ne(t.FullName);
// object o = Activator.Creat eInstance ( t );
....
Check out the types being written to the cosole / debug window and you'll
see what you're attempting to instantiate (which is the type without the
default parameterless constructor.
HTH
Cordell Lawrence
Teleios Systems Ltd.
"brian c" <br****@discuss ions.microsoft. com> wrote in message
news:29******** *************** ***********@mic rosoft.com...
I was under the impression that creating the method CreateTransform () that
contains no parameters would be considered the default contructor. Since
it does not require any parameters I am still confused as to what the problem
is. Could you please elaborate?
public class CreateTransform
{
#region Public Methods
public CreateTransform ()
{
}
public CreateTransform (string sXML, Microsoft.Share Point.SPListIte m
_spListItem)
{
//System.Xml.XmlD ocument xmlDoc;
Microsoft.Share Point.SPAttachm entCollection spAttachColl =
this.GetXSLTran sform(_spListIt em);
this.TransformX ML(sXML,spAttac hColl);
}
#endregion
"Cordell Lawrence" wrote:
The exception is thrown because the type that you're attempting to
creating an instace of does not have a public, parameterless constructor [ That
was already said in your exception dump ]. Advise, you should probably do
some more checking on the type that you're attempting to create an instance
of before calling the Activator.Creat eInstance( ) method.
Some checks may include
- Ensure that the type is not abstract
- Ensure that the type is not an interface ( this one is taken care of
if you check of abstract types ) or enum
- Ensure that the type has a public parameterless constructor
[All of this is predicated on the fact that you really want to instiate
and invoke the methods on your object in this way]
Hope this helps.
Cordell Lawrence [cl*******@telei os-systems.com]
Teleios Systems Ltd.
"System.Reflect ion Activator" <System.Reflect ion
Ac*******@discu ssions.microsof t.com> wrote in message
news:04******** *************** ***********@mic rosoft.com... *************** *************** ********
//Load the Assembly
Assembly a = Assembly.LoadFr om(sAssembly);
//Get Types so we can Identify the Interface.
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.N onPublic | BindingFlags.Pu blic |
BindingFlags.St atic | BindingFlags.In stance |
BindingFlags.De claredOnly);
//Iterate through the Assembly to find Class with a Public Interface.
//****Each Assembly should only have one Public Entry Point****
//****using this method to expose that method and pass the XML data to
it****
foreach (Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(fl ags);
Object obj = Activator.Creat eInstance(t);
*************** *************** ********
I am trying to dynamically call an assembly. The Assembly name is
being pulled from a SharePoint List and in this case it is called
TransformXML. I am getting the following error when it gets to the Activator...
ERROR:
*************** *************** *************** *************
*An unhandled exception of type 'System.Missing MethodException '
occurred in * *mscorlib.dll
*
*
*
*Additional information: No parameterless constructor defined for this
object *
*************** *************** *************** *************
I am also including the code from the class being called.
Transform.dll
*************** *************** *************** *****
public class CreateTransform
{
#region Public Methods
public CreateTransform ()
{
}
public CreateTransform (string sXML, Microsoft.Share Point.SPListIte m
_spListItem)
{
//System.Xml.XmlD ocument xmlDoc;
Microsoft.Share Point.SPAttachm entCollection spAttachColl =
this.GetXSLTran sform(_spListIt em);
this.TransformX ML(sXML,spAttac hColl);
}
#endregion