0

DNN Version: 9.11.0
2sxc Version: 14.11.0

I'm trying to use 2sxc's IRenderService to render a 2sxc module within a DNN skin file (.ascx). I've been using the following resources for reference:

Each of these resources seems to indicate the same essential parts to get this to work:

These three namespaces:

<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="ToSic.Sxc.Dnn" %>
<%@ Import Namespace="ToSic.Sxc.Services" %>

And the following line of code: <%= this.GetScopedService<IRenderService>().Module(8196, 21481) %>

However, whenever I add these parts to my skin file and open a live page using that skin, a 500 error is returned by the server with the following error message in the URL: "Object reference not set to an instance of an object".

<%@ Control language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %>
<%@ Register TagPrefix="dnn" TagName="LANGUAGE" Src="~/Admin/Skins/Language.ascx" %>
<%@ Register TagPrefix="dnn" TagName="LOGO" Src="~/Admin/Skins/Logo.ascx" %>
<%@ Register TagPrefix="dnn" TagName="SEARCH" Src="~/Admin/Skins/Search.ascx" %>
<%@ Register TagPrefix="dnn" TagName="NAV" Src="~/Admin/Skins/Nav.ascx" %>
<%@ Register TagPrefix="dnn" TagName="TEXT" Src="~/Admin/Skins/Text.ascx" %>
<%@ Register TagPrefix="dnn" TagName="BREADCRUMB" Src="~/Admin/Skins/BreadCrumb.ascx" %>
<%@ Register TagPrefix="dnn" TagName="USER" Src="~/Admin/Skins/User.ascx" %>
<%@ Register TagPrefix="dnn" TagName="LOGIN" Src="~/Admin/Skins/Login.ascx" %>
<%@ Register TagPrefix="dnn" TagName="LEFTMENU" Src="~/Admin/Skins/LeftMenu.ascx" %>
<%@ Register TagPrefix="dnn" TagName="LINKS" Src="~/Admin/Skins/Links.ascx" %>
<%@ Register TagPrefix="dnn" TagName="PRIVACY" Src="~/Admin/Skins/Privacy.ascx" %>
<%@ Register TagPrefix="dnn" TagName="TERMS" Src="~/Admin/Skins/Terms.ascx" %>
<%@ Register TagPrefix="dnn" TagName="COPYRIGHT" Src="~/Admin/Skins/Copyright.ascx" %>
<%@ Register TagPrefix="dnn" TagName="STYLES" Src="~/Admin/Skins/Styles.ascx" %>
<%@ Register TagPrefix="dnn" TagName="LINKTOMOBILE" Src="~/Admin/Skins/LinkToMobileSite.ascx" %>
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.DDRMenu.TemplateEngine" Assembly="DotNetNuke.Web.DDRMenu" %>
<%@ Register TagPrefix="dnn" TagName="MENU" src="~/DesktopModules/DDRMenu/Menu.ascx" %>
<%@ Register TagPrefix="dnn" TagName="CONTROLPANEL" Src="~/Admin/Skins/controlpanel.ascx" %>
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<%@ Import Namespace="DotNetNuke.Entities.Modules" %>
<%@ Import Namespace="ToSic.Sxc.Dnn" %>
<%@ Import Namespace="ToSic.Sxc.Services" %>

<%= this.GetScopedService<IRenderService>().Module(8196, 21481) %>
...

Looking at the DNN admin logs, I get the following message:

Message:Unhandled error loading page.

StackTrace:

...error BC30451: 'this' is not declared. It may be inaccessible due to its protection level.

InnerStackTrace:

at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean ensureIsUpToDate)
at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
at DotNetNuke.UI.ControlUtilities.LoadControl\[T\](TemplateControl containerControl, String ControlSrc)
at DotNetNuke.UI.Skins.Skin.LoadSkin(PageBase page, String skinPath)

What does it mean by 'this' is not declared? Am I missing a reference? How can I get this to work as smoothly as it does in the 3 resources I mentioned above?

Zachary
  • 1
  • 4
  • At the moment I can only guess - maybe you're using VisualBasic instead of C#? In that case you would need `Me`. Maybe you can post a larger part of your skin code so we see what's happening... – iJungleBoy Apr 03 '23 at 18:09
  • @iJungleBoy Yes, the skin is written in VisualBasic. Does that mean I need to replace 'this' with 'Me'? I'm unsure of how to modify the below string: <%= this.GetScopedService().Module(8196, 21481) %> – Zachary Apr 03 '23 at 21:56
  • @iJungleBoy Also, I've updated my question with code from my skin file. – Zachary Apr 03 '23 at 22:01
  • Yes, I believe replacing `this` (a c# word) with `Me` should do the trick. Please post if it worked. – iJungleBoy Apr 05 '23 at 06:37
  • Not sure why it's stuck, but just use `ToSic.Sxc.Services.IRenderService` to give it the full namespace. In general I would suggest you consider to switching to C# though ;) – iJungleBoy Apr 06 '23 at 22:04
  • I wasn't ever able to get it working in VB, but I tried it using a skin built with C# and it worked flawlessly. Looks like I'll be switching my skins to C#. Thanks for all your help, @iJungleBoy! – Zachary Apr 21 '23 at 21:43
  • For anybody else searching this, it would help if you wrote a short answer to your own question, stating that you changed to C# and then mark it as answered. – iJungleBoy May 16 '23 at 17:22

1 Answers1

0

See iJungleBoy's comments for a breakdown of the issue.

Ultimately, it appears that 2sxc services can only be activated in skins/modules whose language is set to C#. Updating my skin's language from VB to C# solved the issue.

<%@ Control Language="c#" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin"%>
Zachary
  • 1
  • 4