I am trying to make a module searchable i DNN 9 so I created a class which implements ISearchable and overrides GetSearchItems.
following this documentation: https://www.dnnsoftware.com/wiki/isearchable
public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
{
SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
ArrayList Documents = GetDocuments(ModInfo.ModuleID, ModInfo.PortalID, true);
foreach (var objDocument in Documents)
{
SearchItemInfo SearchItem;
{
var withBlock = (DocumentInfo)objDocument;
int UserId = Null.NullInteger;
// If IsNumeric(.CreatedByUser) Then
// UserId = Integer.Parse(.CreatedByUser)
// End If
UserId = withBlock.CreatedByUserID;
SearchItem = new SearchItemInfo(ModInfo.ModuleTitle + " - " + withBlock.Title, withBlock.Title, UserId, withBlock.CreatedDate, ModInfo.ModuleID, withBlock.ItemId.ToString(), withBlock.Title + " " + withBlock.Category, "ItemId=" + withBlock.ItemId.ToString());
SearchItemCollection.Add(SearchItem);
}
}
return SearchItemCollection;
}
But when I add the namespace of the class in the module manifest, the module disappears from the page (and indexing doesn't work).
The namespace of the class is ProjectName.ListaNews.ListaController
I have also tried ProjectName.ListaNews and changing it to DotNetNuke.Modules.ProjectName.ListaNews.ListaController
I have tried changing the business class controller both from module settings and from .dnn file.
Why adding business class namespace breaks my module and makes it disappear from the page?
-------------- EDIT ----------------
The business controller class name seems to be correct. I checked the log file and found this error:
DotNetNuke.Framework.Reflection - ProjectName.ListaNews.ListaController, ProjectName.ListaNews
System.IO.FileNotFoundException: Could not load file or assembly 'ProjectName.ListaNews' or one of its dependencies.
Cannot find specified file.
File name: 'ProjectName.ListaNews'
in bin\ folder there is ListaNews.dll. I tried renaming it into ProjectName.ListaNews.dll but I had the same error (+ the site crash).
So I changed the business controller class to ListaNews.ListaController, ListaNews without ProjectName and it gave a new error:
DotNetNuke.Framework.Reflection - ListaNews.ListaController, ListaNews
System.TypeLoadException: Could not load type 'ListaNews.ListaController' from assembly 'ListaNews'.
Looks like it didn't find ListaController class.
I noticed ListaController.cs was not defined in .dnn file when I installed it.
I added this to the .dnn file
<component type="File">
other files definitions....
<files>
<file>
<name>ListaController.cs</name>
</file>
</files>
</component>
So I deleted and re-installed my module. Nothing changed though.
Does that give any hint?
Thanks
-------------- EDIT 2 ----------------
Since it was a namespace error I moved the controller class from ListaController.cs to View.ascx.cs and the previous error disappeared, so the class is probably visible now. But the module is still not visible (crashes) so i checked the log and it gave 2 very similiar errors:
1)
Message: Value cannot be null. Parameter name: type
StackTrace: in System.Activator.CreateInstance(Type type, Boolean nonPublic)
in System.Activator.CreateInstance(Type type)
in DotNetNuke.UI.Skins.Pane.IsVesionableModule(ModuleInfo moduleInfo)
in DotNetNuke.UI.Skins.Pane.InjectModule(ModuleInfo module)
in DotNetNuke.UI.Skins.Skin.InjectModule(Pane pane, ModuleInfo module)
InnerMessage: Value cannot be null. Parameter name: type
InnerStackTrace: at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at DotNetNuke.Services.Search.ModuleIndexer.GetModuleList(Int32 portalId)
I read System.Activator.CreateInstance documentation here: https://docs.microsoft.com/it-it/dotnet/api/system.activator.createinstance?view=netcore-3.1#System_Activator_CreateInstance_System_Type_System_Boolean_
and actually CreateInstance has a constructor with type parameter,
But I think it is called in DNN compiled libraries and I can't see what is going on
I added this line in constructor
object instance = Activator.CreateInstance(typeof(ListaController));
and it logged this error:
Error Creating BusinessControllerClass
'ProjectName.ListaNews.ListaController, ProjectName.ListaNews' of
module(ProjectName.ListaNews) id=(577) in tab(45) and portal(0)
StackTrace:
at DotNetNuke.Services.Search.ModuleIndexer.ThrowLogError(ModuleInfo module,
Exception ex)
InnerMessage:Value cannot be null. Parameter name: type
InnerStackTrace:
at System.Activator.CreateInstance(Type type, Boolean nonPublic) at
system.Activator.CreateInstance(Type type) at
DotNetNuke.Services.Search.ModuleIndexer.GetModuleList(Int32 portalId)
I found this forum https://www.dnnsoftware.com/forums/threadid/495897/scope/posts/help-with-rror-in-custom-module so I added a parameterless constructor in my controller class but it didn't change anything
Why is type null in CreateInstance?