I'm working on the Sitecore upgrade from 8.2 to 10.4. Here we have custom link provider and we have changed the code based the new methods but we are getting the error.
Server Error in '/' Application.
Unexpected provider type: Project.Common.Providers.SwitchingLinkProvider. Expected: Sitecore.Links.LinkProvider
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Unexpected provider type: Project.Common.Providers.SwitchingLinkProvider. Expected: Sitecore.Links.LinkProvider
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: Unexpected provider type: Project.Common.Providers.SwitchingLinkProvider. Expected: Sitecore.Links.LinkProvider]
Sitecore.Configuration.DefaultFactory.GetProviders(List`1 nodes) +932
Sitecore.Configuration.DefaultFactory.GetProviders(String rootPath, TProvider& defaultProvider) +323
Sitecore.Configuration.ProviderHelper`2.ReadProviders() +75
Sitecore.Configuration.ProviderHelper`2.get_Provider() +116
Sitecore.Links.DefaultLinkManager.ParseRequestUrl(HttpRequest request) +42
Sitecore.Web.RequestUrl.Parse(HttpRequestBase request) +123
Sitecore.Pipelines.HttpRequest.HttpRequestArgs.Initialize() +31
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +118
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +236
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
Sitecore.Web.RequestEventsHandler.OnBeginRequest(HttpContextBase context) +172
Sitecore.Nexus.Web.HttpModule.HttpApplication_BeginRequest(Object sender, EventArgs e) +121
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +218
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +194
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +100
patch config file
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<linkmanager>
<patch:attribute name="defaultProvider" value="switcher" />
<providers>
<add name="switcher" fallback="sitecore" type="Project.Common.Providers.SwitchingLinkProvider, project.Common" resolve="true" />
</providers>
</linkmanager>
</sitecore>
</configuration>
Class file
public class SwitchingLinkProvider : BaseLinkManager
{
private readonly ProviderHelper<LinkProvider, LinkProviderCollection> _providerHelper;
private const string FALLBACK_ATTRIBUTE_KEY = "fallback";
private const string LINKPROVIDER_ATTRIBUTE_KEY = "linkProvider";
private string Fallback { get; set; }
public SwitchingLinkProvider(ProviderHelper<LinkProvider, LinkProviderCollection> providerHelper)
{
this._providerHelper = providerHelper;
}
protected virtual LinkProvider Provider
{
get
{
var siteLinkProvider = (Sitecore.Context.Site != null)
? Sitecore.Context.Site.Properties[LINKPROVIDER_ATTRIBUTE_KEY] : string.Empty;
if (!string.IsNullOrEmpty(siteLinkProvider))
{
return this._providerHelper.Provider;
}
return this._providerHelper.Providers[siteLinkProvider] ?? this._providerHelper.Provider;
}
}
public override bool AddAspxExtension => this.Provider.AddAspxExtension;
public override bool AlwaysIncludeServerUrl => this.Provider.AlwaysIncludeServerUrl;
public override LanguageEmbedding LanguageEmbedding => this.Provider.LanguageEmbedding;
public override LanguageLocation LanguageLocation => this.Provider.LanguageLocation;
public override bool LowercaseUrls => this.Provider.LowercaseUrls;
public override bool ShortenUrls => this.Provider.ShortenUrls;
public override bool UseDisplayName => this.Provider.UseDisplayName;
public override bool AlwaysExcludeVirtualFolder => throw new System.NotImplementedException();
public override string ExpandDynamicLinks(string text)
{
Assert.ArgumentNotNull(text, nameof(text));
return this.ExpandDynamicLinks(text, false);
}
public override string ExpandDynamicLinks(string text, bool resolveSites)
{
Assert.ArgumentNotNull(text, nameof(text));
return Assert.ResultNotNull<string>(this.Provider.ExpandDynamicLinks(text, resolveSites));
}
//public override ItemUrlBuilderOptions GetDefaultUrlOptions()
//{
// return Assert.ResultNotNull<ItemUrlBuilderOptions>(this.Provider.GetDefaultUrlOptions());
//}
public override string GetDynamicUrl(Item item)
{
return this.GetDynamicUrl(item, LinkUrlOptions.Empty);
}
public override string GetDynamicUrl(Item item, LinkUrlOptions options)
{
return this.Provider.GetDynamicUrl(item, options);
}
public override string GetItemUrl(Item item)
{
return this.Provider.GetItemUrl(item, this.GetDefaultUrlBuilderOptions());
}
public override string GetItemUrl(Item item, ItemUrlBuilderOptions options)
{
return this.Provider.GetItemUrl(item, options);
}
public override bool IsDynamicLink(string linkText)
{
return this.Provider.IsDynamicLink(linkText);
}
public override DynamicLink ParseDynamicLink(string linkText)
{
return this.Provider.ParseDynamicLink(linkText);
}
public override SiteInfo ResolveTargetSite(Item item)
{
Assert.ArgumentNotNull(item, nameof(item));
return this.Provider.ResolveTargetSite(item);
}
public override SiteContext GetPreviewSiteContext(Item item)
{
Assert.ArgumentNotNull(item, nameof(item));
return this.Provider.GetPreviewSiteContext(item);
}
public override ItemUrlBuilderOptions GetDefaultUrlBuilderOptions()
{
throw new System.NotImplementedException();
}
public override RequestUrl ParseRequestUrl(HttpRequest request)
{
throw new System.NotImplementedException();
}
}