No parameterless constructor defined for this object

G

Guest

**************************************
//Load the Assembly
Assembly a = Assembly.LoadFrom(sAssembly);

//Get Types so we can Identify the Interface.
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);

//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(flags);
Object obj = Activator.CreateInstance(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.MissingMethodException' 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.SharePoint.SPListItem
_spListItem)
{
//System.Xml.XmlDocument xmlDoc;

Microsoft.SharePoint.SPAttachmentCollection spAttachColl =
this.GetXSLTransform(_spListItem);

this.TransformXML(sXML,spAttachColl);

}

#endregion
 
D

Dmytro Lapshyn [MVP]

Hi Brian,

Looks like the GetTypes method returns some type which indeed does not have
a public constructor.
You can debug your foreach loop to find out on which type the framework
chokes.
 
G

Guest

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.SharePoint.SPListItem
_spListItem)
{
//System.Xml.XmlDocument xmlDoc;

Microsoft.SharePoint.SPAttachmentCollection spAttachColl =
this.GetXSLTransform(_spListItem);

this.TransformXML(sXML,spAttachColl);

}

#endregion

Dmytro Lapshyn said:
Hi Brian,

Looks like the GetTypes method returns some type which indeed does not have
a public constructor.
You can debug your foreach loop to find out on which type the framework
chokes.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


brian c said:
**************************************
//Load the Assembly
Assembly a = Assembly.LoadFrom(sAssembly);

//Get Types so we can Identify the Interface.
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.DeclaredOnly);

//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(flags);
Object obj = Activator.CreateInstance(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.MissingMethodException' 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.SharePoint.SPListItem
_spListItem)
{
//System.Xml.XmlDocument xmlDoc;

Microsoft.SharePoint.SPAttachmentCollection spAttachColl =
this.GetXSLTransform(_spListItem);

this.TransformXML(sXML,spAttachColl);

}

#endregion
 
D

Dmytro Lapshyn [MVP]

The CreateTransform() method *is* a parameterless constructor. But - it is
not necessary the CreateTransform class is the culptit. That's why I suggest
that you step into the foreach loop in the debugger and see which Type t
causes CreateInstance to fail.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


brian c said:
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.SharePoint.SPListItem
_spListItem)
{
//System.Xml.XmlDocument xmlDoc;

Microsoft.SharePoint.SPAttachmentCollection spAttachColl =
this.GetXSLTransform(_spListItem);

this.TransformXML(sXML,spAttachColl);

}

#endregion

Dmytro Lapshyn said:
Hi Brian,

Looks like the GetTypes method returns some type which indeed does not
have
a public constructor.
You can debug your foreach loop to find out on which type the framework
chokes.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


brian c said:
**************************************
//Load the Assembly
Assembly a = Assembly.LoadFrom(sAssembly);

//Get Types so we can Identify the Interface.
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.DeclaredOnly);

//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(flags);
Object obj = Activator.CreateInstance(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.MissingMethodException'
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.SharePoint.SPListItem
_spListItem)
{
//System.Xml.XmlDocument xmlDoc;

Microsoft.SharePoint.SPAttachmentCollection spAttachColl =
this.GetXSLTransform(_spListItem);

this.TransformXML(sXML,spAttachColl);

}

#endregion
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top