【问题标题】:Why adding business controller class namespace in DNN makes module disappear?为什么在 DNN 中添加业务控制器类命名空间会使模块消失?
【发布时间】:2020-06-17 10:56:32
【问题描述】:

我正在尝试使模块在 DNN 9 中可搜索,因此我创建了一个实现 ISearchable 并覆盖 GetSearchItems 的类。

按照本文档: 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;
    }

但是当我在模块清单中添加类的命名空间时,模块从页面中消失(并且索引不起作用)。

类的命名空间是ProjectName.ListaNews.ListaController

我也尝试过ProjectName.ListaNews 并将其更改为DotNetNuke.Modules.ProjectName.ListaNews.ListaController

我尝试从模块设置和 .dnn 文件中更改业务类控制器。

为什么添加业务类命名空间会破坏我的模块并使其从页面中消失?

------------- 编辑-----

业务控制器类名似乎是正确的。 我检查了日志文件,发现了这个错误:

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'

bin\ 文件夹中有ListaNews.dll。我尝试将其重命名为ProjectName.ListaNews.dll,但我遇到了同样的错误(+ 网站崩溃)。

所以我将业务控制器类更改为ListaNews.ListaController, ListaNews 没有ProjectName,它给出了一个新错误:

DotNetNuke.Framework.Reflection - ListaNews.ListaController, ListaNews
System.TypeLoadException: Could not load type 'ListaNews.ListaController' from assembly 'ListaNews'.

好像没有找到 ListaController 类。

我注意到 ListaController.cs 在安装时没有在 .dnn 文件中定义。

我将此添加到 .dnn 文件中

<component type="File">

    other files definitions....

    <files>
        <file>
        <name>ListaController.cs</name>
        </file>
    </files>
</component>

所以我删除并重新安装了我的模块。不过什么都没有改变。

这有什么提示吗?

谢谢

------------- 编辑 2 ----

由于这是一个命名空间错误,我将控制器类从 ListaController.cs 移动到 View.ascx.cs 并且之前的错误消失了,因此该类现在可能是可见的。但是模块仍然不可见(崩溃)所以我检查了日志,它给出了 2 个非常相似的错误:

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)

我在这里阅读 System.Activator.CreateInstance 文档: https://docs.microsoft.com/it-it/dotnet/api/system.activator.createinstance?view=netcore-3.1#System_Activator_CreateInstance_System_Type_System_Boolean_

实际上 CreateInstance 有一个带有type 参数的构造函数, 但我认为它是在 DNN 编译库中调用的,我看不到发生了什么

我在构造函数中添加了这一行

object instance = Activator.CreateInstance(typeof(ListaController));

它记录了这个错误:

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)

我找到了这个论坛 https://www.dnnsoftware.com/forums/threadid/495897/scope/posts/help-with-rror-in-custom-module 所以我在控制器类中添加了一个无参数构造函数,但它没有改变任何东西

为什么 CreateInstance 中的 type 为空?

【问题讨论】:

  • 当控制器定义不正确(可能只是命名)时会发生这种情况。如果您查看 /portals/_default/logs 中的 LOGS,您可能会获得有关错误的更多详细信息。
  • 谢谢克里斯,我检查了日志并用新信息编辑了问题
  • 您无需在 .DNN 文件中注册 CS 文件。
  • 这绝对是命名空间问题,请确保命名空间已正确列出以及正确的 DLL。
  • @ChrisHammond 这是一个命名空间错误,我修复了它,现在我得到一个不同的错误。我用新的细节编辑了问题(在“编辑 2”段落中)

标签: search module controller dotnetnuke


【解决方案1】:

清单中businessControllerClass 的值必须采用{FQCN}, {Assembly} 格式。这是The manifest schema

对于您的项目,假设命名空间是您提到的 ProjectName.ListaNews.ListaController,您的程序集名称很可能是 ProjectName.ListaNews,这意味着 businessControllerClass 的正确值是

ProjectName.ListaNews.ListaController, ProjectName.ListaNews

如果这不能纠正它,正如 Chris Hammond 所说,您可以使用日志来获取更详细的错误

【讨论】:

  • 谢谢米切尔,我用新的细节编辑了这个问题。业务控制器类格式与您建议的相同,但使用不同的命名空间可能会改变某些内容(始终保持 FQCN、Assembly 格式)。
猜你喜欢
  • 2016-04-30
  • 2023-04-04
  • 2017-11-15
  • 1970-01-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多