0

I am trying to replace all the Deprecated EventLoggerController code in my DotNetNuke (DNN) Modules.

I had a look at an answer someone posted on a previous question I had and also another question asked by someone.

  1. DNN 9.8 - EventLogController is obsolete - Does anyone have an example on how to use the Dependency Injection method to fix this error?
  2. Why am I getting the error "Cannot instantiate implementation type" for my generic service?

I also had a look at this article regarding DNN webforms using Dependency Injection: https://www.andrewhoefling.com/Blog/Post/dnn-dependency-injection-webforms-modules

enter image description here

I am getting the following error: enter image description here

I have added a Startup.cs file to my DNN module project: enter image description here

I have added the following code to my code behind file:

private readonly IEventLogger _eventLogger;

public View()
{
  _eventLogger = DependencyProvider.GetRequiredService<IEventLogger>();
}

enter image description here

Logging the exception: enter image description here

I assume something is wrong with my Startup.cs file.

Tig7r
  • 525
  • 1
  • 4
  • 21
  • What is your actual question? Are there any errors after your changes? Or is it simply not logging? I suspect you have to change the two lines in your last code snippert, because as far as I understood it Exceptions.ProcessModuleLoadException() will end the code and return. So the line with the logging will not be reached... – Michael Tobisch Mar 15 '22 at 09:56
  • So the issue I am having is that even before it reaches a breakpoint near my catch on my module, I get a "Cannot instantiate implementation type 'DotNetNuke.Abstractions.Logging.IEventLogger' for service type 'DotNetNuke.Abstractions.Logging.IEventLogger'." when I load any page without the module. I think it has something to do with the startup.cs file I added for that particular module. The startup.cs file is not in the root of the DNN site, but under the specific DNN modules folder. I think this code is perhaps wrong: DependencyProvider.GetRequiredService(); – Tig7r Mar 15 '22 at 15:07
  • Then I would try to add a try-catch construct around this line and see what happens... – Michael Tobisch Mar 16 '22 at 09:44
  • I have added a try-catch to the Startup.cs file, but I see it never throws an error in the catch. I have even checked the Page_Load method and it also does not go in the catch. The page loads with the message "Cannot instantiate implementation". Do you perhaps have an example of your Startup.cs file? – Tig7r Apr 07 '22 at 12:54
  • I think I figured out the issue. I am using a WebForm DNN module and I don't need a Startup.cs file yet. It seems that it will be added to DNN version 10 and up if I understand correctly. Thx for the help. – Tig7r Apr 07 '22 at 13:39

1 Answers1

0

I am using a DNN module that uses WebForms and it seems like it does not require a Startup.cs file yet. It seems that it will be added from DNN version 10 and up.

I also had a look at this forum question: https://dnncommunity.org/forums/aft/2002

Tig7r
  • 525
  • 1
  • 4
  • 21