0
votes

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?

1
This happens when the controller isn't defined properly (likely just naming). If you look at the LOGS in /portals/_default/logs you might get more details on the error. - Chris Hammond
Thanks Chris, I checked the log and edited the question with new information - fatgL
You won't need to register the CS file in the .DNN file. - Chris Hammond
This is definitely a namespace issue, make sure that the namespace is correctly listed and the proper DLL. - Chris Hammond
@ChrisHammond It was a namespace error, I fixed it and now I get a different error. I edited the question with new details (in "EDIT 2" paragraph) - fatgL

1 Answers

0
votes

The value for businessControllerClass in the manifest must be in the format {FQCN}, {Assembly}. This is per The manifest schema

For your project, assuming the namespace is as you mentioned ProjectName.ListaNews.ListaController your assembly name is most likely ProjectName.ListaNews which would mean the proper value for the businessControllerClass is

ProjectName.ListaNews.ListaController, ProjectName.ListaNews

If that doesn't correct it, as Chris Hammond mentioned you can use the logs to get a more detailed error