I
ismail.mayat
Hello,
I am having a problem with Activator.CreateInstance. I have the
following code
Assembly asm = System.Reflection.Assembly.LoadFrom(assembly);
if(asm!=null)
{
try
{
foreach (Type t in asm.GetTypes())
{
Type hasInterface =
t.GetInterface("umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter",
true);
//writeOutInterfaces(hasInterface);
if (hasInterface != null && !t.IsInterface)
{
//fails here
umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter typeInstance =
Activator.CreateInstance(t) as
umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter;
string extensions = ",";
if(typeInstance!=null)
{
foreach(string ext in typeInstance.extensions)
{
extensions += ext + ",";
_filters.Add(extensions,typeInstance);
System.Web.HttpContext.Current.Trace.Write("umbracoUtilities.Search.FileFilterFactory",
" + Adding searchfilter for extensions '" + extensions + "'");
}
}
else{
System.Web.HttpContext.Current.Trace.Warn("umbracoUtilities.Search.FileFilterFactory",
" + Could not get instance for " +t.ToString() + " in '" + assembly +
"'");
}
}
}
}
catch (Exception factoryE)
{
System.Web.HttpContext.Current.Trace.Warn("umbracoUtilities.Search.FileFilterFactory",
"error while processing assembly " + assembly, factoryE);
}
}
It all works upto to the comment //fails here . The assembly is loaded
fine the if checks all work and when it gets to
Activator.CreateInstance the type it is trying to create definately
implements the interface specified. Also the type it is trying to
create has a parameterless constructor. I do not get any errors anyone
any suggestions ?
Many thanks in advance
Ismail
I am having a problem with Activator.CreateInstance. I have the
following code
Assembly asm = System.Reflection.Assembly.LoadFrom(assembly);
if(asm!=null)
{
try
{
foreach (Type t in asm.GetTypes())
{
Type hasInterface =
t.GetInterface("umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter",
true);
//writeOutInterfaces(hasInterface);
if (hasInterface != null && !t.IsInterface)
{
//fails here
umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter typeInstance =
Activator.CreateInstance(t) as
umbracoUtilities.Businesslogic.IUmbracoSearchFileFilter;
string extensions = ",";
if(typeInstance!=null)
{
foreach(string ext in typeInstance.extensions)
{
extensions += ext + ",";
_filters.Add(extensions,typeInstance);
System.Web.HttpContext.Current.Trace.Write("umbracoUtilities.Search.FileFilterFactory",
" + Adding searchfilter for extensions '" + extensions + "'");
}
}
else{
System.Web.HttpContext.Current.Trace.Warn("umbracoUtilities.Search.FileFilterFactory",
" + Could not get instance for " +t.ToString() + " in '" + assembly +
"'");
}
}
}
}
catch (Exception factoryE)
{
System.Web.HttpContext.Current.Trace.Warn("umbracoUtilities.Search.FileFilterFactory",
"error while processing assembly " + assembly, factoryE);
}
}
It all works upto to the comment //fails here . The assembly is loaded
fine the if checks all work and when it gets to
Activator.CreateInstance the type it is trying to create definately
implements the interface specified. Also the type it is trying to
create has a parameterless constructor. I do not get any errors anyone
any suggestions ?
Many thanks in advance
Ismail