Try our conversational search powered by Generative AI!

Object null Reference issue in StructureMap - Episerver 11.9.2

Vote:
 

Hi Team,


I used below code in dependencyResolver ,


public void ConfigureContainer(ServiceConfigurationContext context)
{
 context.StructureMap().Configure(ConfigureContainer);

 var dependencyResolver = new StructureMapDependencyResolver(context.StructureMap());

 DependencyResolver.SetResolver(dependencyResolver); ////mvc

 GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver; ////web api

}




But I faced null exception. Below the Error StackTrace,


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
EPiServer.Web.Hosting.VirtualPathRegistrationHandler.CreateVirtualPathProviderInstance(ProviderSettings providerSettings) +41
EPiServer.Web.Hosting.VirtualPathRegistrationHandler.RegisterVirtualPathProvidersFromSettings(ProviderSettingsCollection settings) +99
EPiServer.Web.Hosting.VirtualPathRegistrationHandler.RegisterVirtualPathProviders(InitializationEngine context, ProviderSettingsCollection settings) +34
EPiServer.Framework.Initialization.Internal.VirtualPathProviderInitialization.RegisterVirtualPathProviders(InitializationEngine context) +126
EPiServer.Framework.Initialization.Internal.VirtualPathProviderInitialization.Initialize(InitializationEngine context) +7
EPiServer.Framework.Initialization.Internal.<>c__DisplayClass2_0.b__0() +19
EPiServer.Framework.Initialization.Internal.ModuleNode.Execute(Action a, String key) +52
EPiServer.Framework.Initialization.Internal.ModuleNode.Initialize(InitializationEngine context) +80
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +179

[InitializationException: Initialize action failed for Initialize on class EPiServer.Framework.Initialization.Internal.VirtualPathProviderInitialization, EPiServer.Framework.AspNet, Version=11.9.2.0, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]
EPiServer.Framework.Initialization.InitializationEngine.InitializeModules() +492
EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions) +153
EPiServer.Framework.Initialization.InitializationEngine.Initialize() +40
EPiServer.Framework.Initialization.<>c.b__7_0(InitializationEngine e) +9
EPiServer.Framework.Initialization.InitializationModule.EngineExecute(HostType hostType, Action`1 engineAction) +462
EPiServer.Framework.Initialization.InitializationModule.FrameworkInitialization(HostType hostType) +170
EPiServer.Global..ctor() +44
SnS.EPiServerApplication..ctor() +42
ASP.global_asax..ctor() in c:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\root\945d8f11\87aa1f56\App_global.asax.0.cs:0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark) +1117
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +124
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture) +20
System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[] args) +59
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +287
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +772
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +195





Its due to the Episerver Upgrade ( from 10.2.1 - to 11.9.2 ).  I removed the old version of StructureMap too. Is there any configuration missed ?  Kindly help me out.


Thanks in Advance.


Regards,

krishna.




#195026
Jul 11, 2018 13:13
Vote:
 

From the stack trace it seems that there is some failure when it tries to create instance of VirtualPathProviders according to configuration in web.config. They are specified under setting <episerver.framework><virtualPathProviders>  in web.config. 

Do you have any provider that is from assembly EPiServer.Framework? If so change assembly to EPiServer.Framework.AspNet

#195028
Jul 11, 2018 13:38
Vote:
 

Thanks Johan,



Already its updated during upgrade, 

  <virtualPathProviders>
      <clear />
      <add name="ProtectedModules" virtualPath="~/EPiServer/" physicalPath="Modules\_Protected" type="EPiServer.Web.Hosting.VirtualPathNonUnifiedProvider, EPiServer.Framework.AspNet" />
      <add name="CustomUrlMapping" type="EPiServer.Web.Hosting.VirtualPathMappedProvider, EPiServer" />
    </virtualPathProviders>


Eventhough getting error.

#195031
Edited, Jul 11, 2018 14:06
Vote:
 

This should be changed to EPiServer.Framework.AspNet instead

      <add name="CustomUrlMapping" type="EPiServer.Web.Hosting.VirtualPathMappedProvider, EPiServer" />
#195049
Jul 12, 2018 8:35
Vote:
 

Thanks Quan,

Its Worked. Updated code below,

<virtualPathProviders>
      <clear/>
      <add name="ProtectedModules" virtualPath="~/EPiServer/" physicalPath="Modules\_Protected" type="EPiServer.Web.Hosting.VirtualPathNonUnifiedProvider, EPiServer.Framework.AspNet"/>
      <add name="CustomUrlMapping" type="EPiServer.Web.Hosting.VirtualPathMappedProvider, EPiServer.Framework.AspNet"/>
    </virtualPathProviders>

But, Am not able to call the WebApi..

#195063
Edited, Jul 12, 2018 13:11
Vote:
 

You might find the solution here https://stackoverflow.com/questions/19969228/ensure-that-httpconfiguration-ensureinitialized 

#195064
Jul 12, 2018 13:19
Vote:
 

Ya Quan, I tried that too in earlier, which you mentioned in above answer..





   protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            GlobalConfiguration.Configure(Infrastructure.ApiControllers.WebApiConfig.Register);

            RegisterGlobalFilters(GlobalFilters.Filters);

            GlobalConfiguration.Configuration.EnsureInitialized();
            ////Tip: Want to call the EPiServer API on startup? Add an initialization module instead (Add -> New Item.. -> EPiServer -> Initialization Module)
        }


Eventhough getting error.

#195067
Jul 12, 2018 13:42
Vote:
 

Commented that code like below,


   protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            BundleConfig.RegisterBundles(BundleTable.Bundles);
           //// GlobalConfiguration.Configure(Infrastructure.ApiControllers.WebApiConfig.Register);
            RegisterGlobalFilters(GlobalFilters.Filters);
            ////Tip: Want to call the EPiServer API on startup? Add an initialization module instead (Add -> New Item.. -> EPiServer -> Initialization Module)
        }


Instead of this, I Added that line in ConfigurationContainer method.

 public void ConfigureContainer(ServiceConfigurationContext context)
        {
                context.StructureMap().Configure(ConfigureContainer);
                var dependencyResolver = new StructureMapDependencyResolver(context.StructureMap());
                DependencyResolver.SetResolver(dependencyResolver); ////mvc
                GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver; ////web api
                GlobalConfiguration.Configure(config =>
                {
                    WebApiConfig.Register(config);
                    config.Services.Add(typeof(IExceptionLogger), new WebApiExceptionLogger());
                });
        }


Its working now. Is this Correct?  Little bit worried for below thing,

Because 

 RegisterGlobalFilters(GlobalFilters.Filters);


Its registered in app_start but web api config called after this in dependencyresolverinitilization class .


Will it affect any other case ? Is that fine ?

 

#195079
Edited, Jul 12, 2018 16:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.