Exception on RoutingSegmentValidator on start up after upgrade

Vote:
 

Hi!

After upgrade to CMS 12 I get this excpetion on startup?

fail: Microsoft.Extensions.Hosting.Internal.Host[11]
      Hosting failed to start
      System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       ---> System.AggregateException: One or more errors occurred. (Value cannot be null. (Parameter 'collection'))
       ---> System.ArgumentNullException: Value cannot be null. (Parameter 'collection')
         at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
         at EPiServer.Validation.Internal.RoutingSegmentValidator..ctor(LocalizationService localizationService, IUrlSegmentLocator urlSegmentLocator, IContentTypeRepository contentTypeRepository, IContentRepository contentRepository, IUrlSegmentGenerator urlSegmentGenerator, UrlSegmentOptions urlSegmentOptions)
         at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
         at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
         at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
         at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
         at EPiServer.Validation.Internal.ValidationService.Initialize(ITypeScannerLookup typeScannerLookup, IServiceProvider serviceProvider)
         at EPiServer.Validation.Internal.ValidationService.<>c__DisplayClass13_0.<Initialize>b__0()
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
         at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
         at System.Threading.Tasks.Task.Wait()
         at EPiServer.Validation.Internal.ValidationService.<>c__DisplayClass13_0.<Initialize>b__1(Object e, EventArgs args)
         at InvokeStub_EventHandler.Invoke(Object, Span`1)
         at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         --- End of inner exception stack trace ---
         at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         at System.Delegate.DynamicInvokeImpl(Object[] args)
         at EPiServer.Framework.Initialization.InitializationEngine.OnInitComplete()
         at EPiServer.Framework.Initialization.InitializationEngine.ExecuteTransition(Boolean continueTransitions)
         at EPiServer.Framework.Initialization.InitializationEngine.Initialize()
         at EPiServer.Hosting.Internal.EPiServerFrameworkHost.StartAsync(CancellationToken cancellationToken)
         at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
         at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)

Any ideas?

Thanks!

/Kristoffer

#314556
Dec 22, 2023 13:17
Vote:
 

It appears urlSegmentOptions.ReservedSegments is null. It should have been set using SetDefaultValues(), but you can work around by adding the settings for it, the default value is 

{"bin", "app_code", "app_globalresources", "app_localresources", "app_webreferences", "app_data", "app_browsers"}

#314557
Dec 22, 2023 13:54
Vote:
 

Added this:

services.Configure<UrlSegmentOptions>(_configuration => _configuration.ReservedSegments = new List<string>
{
    "bin",
    "app_code",
    "app_globalresources",
    "app_localresources",
    "app_webreferences",
    "app_data",
    "app_browsers"
});

But still the same error. Strange. Could it be some old routing code still left from CMS 11 or something?

Thanks!

#314560
Dec 22, 2023 14:33
Vote:
 

Could you start your site in debug mode and uncheck just my code option, to see if you can see which parameter is null?

i just dug into it and SetDefaultValues should be called before ValidationService.Initialize, so I'm not sure what is wrong here 

#314561
Dec 22, 2023 14:50
Vote:
 

Unchecking Just My Code didn't give me anything differentm but I see that I did not send you this before:

ArgumentNullException: Value cannot be null. Arg_ParamName_Name

Does that say anything?

#314562
Dec 22, 2023 14:56
Vote:
 

Wish I had a better thing to say but it seems you need to contact developer support service. if this is reproduced it would be much easier to diagnose 

#314563
Dec 22, 2023 15:34
Vote:
 

Took me longer than expected, but (as I commented in the ticket), this was because of your IriConfigurationModule 

         context.Services.RemoveAll<UrlSegmentOptions>();

            context.Services.AddSingleton(typeof(UrlSegmentOptions), s => new UrlSegmentOptions
           

{                 SupportIriCharacters = true,                 ValidCharacters = @"\p\{L}0-9-_~\.\$" + validChars,
                UseLowercase = true
            });

you can set the ReservedSegments here as you wish

this happens after the Configure which is why it overrides the setting you added, but before any Initialize which is when the ValidationService is called (and caused your exception)

#315402
Jan 10, 2024 12:50
Vote:
 

Thanks Quan! I'm not sure why this is used actually but I will remove the file and move it ot Startup.cs

#315404
Jan 10, 2024 13:27
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.