1

We are using a fresh Sitecore 10 instance in local and trying to set up Leprechaun for generating C# class for respective template and serialization of Sitecore Items under Visual studio solution.

  • Placed config file under "src" folder - \src\Leprechaun.config

  • Placed *.*.module.json under src\Feature\PageContent\Feature.PageContent.module.json

      <configurations import="**\*.module.json">
      <!--
          Base code generation configuration.
          Use this abstract configuration to override the <defaults> where needed.
          (leave defaults alone to make config upgrades simpler)
      -->
      <configuration name="DemoSite.Helix" abstract="true">
          <codeGenerator scripts="$(configDirectory)\Scripts\Glassmapper.csx" outputFile="$(configDirectory)\$(layer)\$(module)\code\$(layer).$(module).Model.cs" />
          <typeNameGenerator type="Leprechaun.MetadataGeneration.StandardTypeNameGenerator, Leprechaun" singleInstance="true" namespaceRootPath="/sitecore/templates/$(layer)/$(module)" keepLeadingUnderscores="false" />
          <templatePredicate rootNamespace="DemoSite.$(layer).$(module).Templates">
              <include name="Templates" path="$(layer)/$(module)" />
          </templatePredicate>
      </configuration>
      <configuration name="DemoSite.Base" abstract="true">
          <codeGenerator scripts="$(configDirectory)\Scripts\Glassmapper.csx" outputFile="$(configDirectory)\$(layer)\$(module)\code\$(layer).$(module).Model.cs" />
          <typeNameGenerator type="Leprechaun.MetadataGeneration.StandardTypeNameGenerator, Leprechaun" singleInstance="true" namespaceRootPath="/sitecore/templates/$(layer)/DemoSite/$(module)" keepLeadingUnderscores="false" />
          <templatePredicate rootNamespace="DemoSite.$(layer).$(module).Templates">
              <include name="Templates" path="$(layer)/PennFoster/$(module)" />
          </templatePredicate>
      </configuration>
    
      <configuration name="DemoSite.Scaffolding.Base" abstract="true">
          <codeGenerator scripts="$(configDirectory)\Scripts\Glassmapper.csx" outputFile="$(configDirectory)\Foundation\Scaffolding\code\$(module).Scaffolding.Model.cs" />
          <typeNameGenerator type="Leprechaun.MetadataGeneration.StandardTypeNameGenerator, Leprechaun" singleInstance="true" namespaceRootPath="/sitecore/templates/$(layer)/$(module)" keepLeadingUnderscores="false" />
          <templatePredicate rootNamespace="$(module).Foundation.Scaffolding.$(module)Templates" />
      </configuration>
    
    {
    "namespace": "Feature.PageContent",
    "items": {
      "includes": [
        {
          "name": "Projects.Feature.PageContent.Templates",
          "allowedPushOperations": "createUpdateAndDelete",
          "database": "master",
          "maxRelativePathLength": "120",
          "scope": "itemAndDescendants",
          "path": "/sitecore/templates/Feature/DemoSite/PageContent"
        },
        {
          "name": "Projects.Feature.PageContent.Renderings",
          "path": "/sitecore/layout/renderings/Feature/PageContent",
          "allowedPushOperations": "createUpdateAndDelete",
          "database": "master",
          "maxRelativePathLength": "120",
          "scope": "itemAndDescendants"
        }
      ]
    },
    "leprechaun": {
      "configuration": {
        "@extends": "DemoSite.Helix",
        "@name": "Feature.PageContent"
      }
    }
    }
    

When we run command "dotnet leprechaun /c "C:\Source\Demo\DemoSite\src\Leprechaun.config" we are getting below exception -

Unhandled exception. Configy.Containers.MicroResolutionException: Cannot activate Leprechaun.InputProviders.Sitecore.Filters.SitecoreTemplatePredicate, constructor param 'leprechaunModuleFactory' (LeprechaunModuleFactory). The type 'LeprechaunModuleFactory' is probably not registered, or may need to be an explicit unmapped parameter (as an XML attribute on the type registration). Inner message: Cannot construct Sitecore.DevEx.Serialization.Client.Datasources.Filesystem.Formatting.Yaml.YamlSerializationFormatter because it has > 1 public constructor.
   at Configy.Containers.MicroContainer.Activate(Type type, KeyValuePair`2[] unmappedConstructorParameters)
   at Configy.XmlContainerBuilder.<>c__DisplayClass5_0.<RegisterConfigTypeInterface>b__0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Configy.Containers.MicroContainer.Resolve(Type type)
   at Configy.Containers.MicroContainer.Resolve[T]()
   at Leprechaun.InputProviders.Sitecore.SitecoreOrchestrator.GetTemplates(IContainer configuration) in D:\a\1\s\src\Leprechaun.InputProviders.Sitecore\SitecoreOrchestrator.cs:line 54
   at Leprechaun.InputProviders.Sitecore.SitecoreOrchestrator.GetAllTemplates(IEnumerable`1 configurations) in D:\a\1\s\src\Leprechaun.InputProviders.Sitecore\SitecoreOrchestrator.cs:line 43
   at Leprechaun.InputProviders.Sitecore.SitecoreOrchestrator.GenerateMetadata(IContainer[] configurations) in D:\a\1\s\src\Leprechaun.InputProviders.Sitecore\SitecoreOrchestrator.cs:line 26
   at Leprechaun.Execution.Runner.GenerateMetadata(IOrchestrator orchestrator, LeprechaunConfigurationBuilder configuration) in D:\a\1\s\src\Leprechaun\Execution\Runner.cs:line 123
   at Leprechaun.Execution.Runner.Run(IRuntimeArgs parsedArgs) in D:\a\1\s\src\Leprechaun\Execution\Runner.cs:line 34
   at Leprechaun.Cli.Program.Run(ConsoleArgs parsedArgs, CommandLineParser argsParser) in D:\a\1\s\src\Leprechaun.Cli\Program.cs:line 54
   at Leprechaun.Cli.Program.Main(String[] args) in D:\a\1\s\src\Leprechaun.Cli\Program.cs:line 28
1
  • @ben-lipson , We followed the suggestion on given article but getting some error while generating code
    – Abhi
    Nov 30, 2021 at 16:35

1 Answer 1

2

Without seeing your full Leprechaun.config file or knowing the version of Leprechaun, I can't say for certain. However, I believe the problem is the <serializationFormatter> section towards the bottom.

The type for the latest version of Leprechaun should be:

Leprechaun.InputProviders.Sitecore.YamlSerializationFormatterWrapper, Leprechaun.InputProviders.Sitecore.

I suspect you have it set to the previous version (for Sitecore CLI 3.0) which was:

Sitecore.DevEx.Serialization.Client.Datasources.Filesystem.Formatting.Yaml.YamlSerializationFormatter, Sitecore.DevEx.Serialization.Client.

Sitecore CLI made some changes with 4.0 which weren't backwards compatible with Leprechaun.

I recommend whenever upgrading Leprechaun, please compare your Leprechaun.config against the one from the GitHub repo that's tagged with the same version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.