XM Cloud - SXASTARTER Kit Setting up Leprechaun Exited with Code 1 Error

May 21, 2023 ·

XM Cloud - SXASTARTER Kit Setting up Leprechaun Exited with Code 1 Error

Hi Team,

We all have been using Code Generators like Glass Mapper for our applications, Today in this post we will see the error which comes when you run leprechaun against XM Cloud starter repository, Steps for setting up leprechaun which are universal step & there is nothing major and very well documented at Leprechaun, So we will not discuss those step, You can easily configure it from the leprehaun site.

Leprechaun is a universal, open API for code generation from Rainbow serialized or Sitecore serialized Sitecore templates. Leprechaun uses state-of-the-art Roslyn code generation technology instead of T4 templates for speedy generation that doesn't require Visual Studio.

(Taken from https://github.com/blipson89/Leprechaun)

Leprechaun is very well documented, so i will not talk much about it  But i will share some info where we were blocked for more than a week for which there was nothing available on the internet and those information i will share so you do not end up in the same issue

Scenario

We have used leprechaun for our couple of projects, and over there we had no major issues and it all worked fine for us (They were not on XM cloud Sxastarter repository, They were all on-prem XM), But recently we run into an issue for XM Cloud based code based, were we kept getting an exception from leprechaun "Leprechaun command exited with code 1"

I did so many changes to my configurations & also my leprechaun file to find out where could be the issue, but i was no where, it was always giving me this error, Steps i followed were

1) I changed my leprechaun to point to some wrong path of module.json in <configuration> node where we give path to module.json, there was no error and it all went and gave me proper messages back saying, there was no module found for which it can generate the code.

2) I also changed different code generation file, giving all of those at once and also tied giving them one by one by it was giving same error as "Exited with Code 1"

3) I tried switching to diagnosed modes in visual studio from tools->Options and in that Projects & solutions-> Build And Run and on right hand side, select "MSBuild project build output verbosity" to "Diagnostic" thinking that it might give something, but no luck, same error.

4) Uninstalled & install leprechaun again, but no luck

5) I compared with my on-prem projects with my XM Cloud and lepreachaun configurations were same and identical.

6) I tried it with simplest of the template thinking may be it could be templates causing issue, but same error.

7) Sometimes if you download the code generation files, they are generally blocked by default, so i also double checked that they are unblocked and have proper access, all good but same error.

With no clue, i reached out to leprechaun mentioning the behavior and thank you to ben lipson for getting on a call for this, and in our first call there was no clue, he was also surprised why there is no details of error and why its not working

Final Solution & Steps

ben lipson and i remained in touch for next couple of days to figure out  the issue, He update the nuget with some more logs via which we can figure out the issue, i updated my leprechaun with that and it worked, we got some error like following 


We were more interested in the error where it says "Endpoint dev was missing Authority (STS/Identity Server/AAD tenant URL) System.AggregateException"

This is where i felt it's something to do with the configuration either in leprechaun or on code, now ben lipson put more light on this where he mentioned about following code getting executed from leprechaun

The code in leprechaun at Leprechaun/ModuleConfigurationReader.cs at main · blipson89/Leprechaun (github.com)

That call is to Sitecore.DevEx.Configuration.FilesystemConfigurationManager, which resolves the sitecore.json file and calls Validate(). It's the Validate that's failing, indicating something is wrong with the Sitecore configuration.

So we looked into validate() method and that error was getting thrown from that code 
 

 


Now, because it was mentioning DEV end point and it uses sitecore.json file, I recollect that there is only one file where end points are mentioned and that is user.json file


So, i opened up user.json file and tried to observe it and with my surprise, authority which the error is mentioning was mentioned only in "XmCloud" ref and for all other environment like "dev", "local" there was no authority url mentioned, see below

 


 Now, this user.json file is created automatically and we do not change it manually, and it is not committed to source control too


But i just changed all the environment "dev", "local" and where ever the authority was not present and gave the value "https://auth.sitecorecloud.io/", Now i just tried to run the laprechaun again and i was so happy to see that it generated the model successfully and "exited with code 1" error was no more there and models got successfully created

 


 

Conclusion

I still have not figured out why my user.json do not have the authority url in all environment, but putting it to the above values works just fine

I reached out to sitecore too because,

 

The problem is that the command "dotnet sitecore cloud environment connect" does not require an authority to be passed, because the cloud plugin will assume that the authority is auth.sitecorecloud.io if it's blank.

However, Leprechaun doesn't use the cloud plugin, because it doesn't actually need to connect to Sitecore

Leprechaun isn't connecting to xm cloud. It's just using the devex API to find the yaml files. However, the devex api calls Validate, which might detected a problem with your user.json file, despite not actually needing to use it, and that is where i have reached out to sitecore

My other colleagues also facing the same issue and they also do not have authority in their user.json file, i am not sure why, All of they do not have it, so not sure what is the permanent solution to this, because we all are using standard sitecore xm cloud documentation located at https://doc.sitecore.com/xmc/en/developers/xm-cloud/walkthrough--setting-up-your-full-stack-xm-cloud-local-development-environment.html and the commands given there.

ben lipson will be changing the leprechaun code and releasing a new version which will output more error where it will mention the exact issue, which it is not outputting right now, so by looking it at it we can do the needed change, but the solution is to add "authority" url to all the environment if not present and run the leprechaun afterwards.

Note: This issue exists only in sxastarter repository because it contains multiple end points in user.json file.






XM Cloud - Site folder not visible in "insert from template" dialog box

May 13, 2023 ·

XM Cloud - Site folder not visible in "insert from template" dialog box

Hi Team,

Recently, While working on XM Cloud, I ran into wired issue, I did create multiple sites and create templates inside templates->Project-><<my sites folder>>

Now i wanted to now start creating pages from those templates, so i right clicked on my home item of the site and selected "insert from template" option so i can select my "Blog Folder" template and can start creating my Blog items inside it, But with my surprise, it was not showing my site folder at all and i was puzzled as to how do i select my template and why it is not showing those folder? and surprisingly other site which i have it was showing it fine


My template->Project folder actually had those site folders and templates inside it


Solution

I just compared both folder's template and with my surprise the one which was showing fine i.e "TrainingLab" had "/sitecore/templates/System/Templates/Template Folder" and the other site which was not showing had "/sitecore/templates/Foundation/Experience Accelerator/Multisite/Project Folder "

i did not know the reason why both were different, but may be "TrainingLab" was not created locally, but it was created in Cloud by using "Create Site" button, and pulled into my local using serialization, while the other one "BasicSiteA" was created locally using "Create headless site" option when you right click on "Headless Site Collection", So may be there is some different scaffolding happening in different processes.

But i decided to change the template of my "BasicSiteA" to "/sitecore/templates/System/Templates/Template Folder", i just did that and it started showing in the "Insert from Template" dialog


Because i was unsure of what will be consequences of this change, i decided to raise a support ticket and ask them about this behavior and they came up with following

I am able to reproduce the same behavior in my XM cloud instance and the reported behavior is not expected. This behavior has been registered as a bug in our bug tracking system. Thank you for reporting the problem.
To track the future status of this bug report, please use reference number 582905. 
More information about public reference numbers can be found here: https://support.sitecore.com/kb?id=kb_article_view&sysparm_article=KB0853187
 
As you have reported in the ticket earlier, the workaround of this issue is to replace the template with /sitecore/templates/System/Templates/Template Folder - {0437FEE2-44C9-46A6-ABE9-28858D9FEE8C}. Unfortunately, this is the only workaround that we are aware of.

 So until the bug is resolved this is the correct workaround to get unblocked, I hope this will help others finding the solution to this puzzle

XM Cloud - Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies

May 10, 2023 ·

XM Cloud - Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies

Hello Folks,

Today's blog post is to share one of the weirdest behavior i came across while working with Sitecore XM Cloud head repository.

I worked on it for couple of days, Created new projects for custom resolver and tested everything in local, and all the time i was using publishing profile and it was just working fine.

But out of the blue my local started getting below exception

Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


Looking at error you generally match dll versions, web.config had different bindings and bin also had same file but somehow my docker->deploy->Platform->bin was getting 5.2.6.0 version instead of 5.2.7.0

but suddenly i realized, my docker->deploy->Platform->bin should only have those DLLs which are my custom code, my project DLLs but it had all DLLs and that broke the whole site

So actual issue was my docker->deploy->platform->bin folder should only have those file which are either of custom projects & platform DLLs, but in my bin i had all sorts of DLLs being copied, see below screenshot, Instead of all DLLs, it should only have my custom DLLs of project.


 

So, I tried below steps 

1) I cleared package manager cache

2) Removed all reference of the project from platform & again redeployed

3) I changed from debug to release in publish profile configuration like below 

<LastUsedBuildConfiguration>Release</<LastUsedBuildConfiguration>

3) Deleted BIN and changed the publish folder path in my config to something else instead of platform, as out of the clue just wanted to see there is nothing related to that, but with my surprise it only copied my custom DLLs

4) I cleaned the project and build it again & republished again, and the most wired thing, it copied all those DLLs again and again i run into DLL hell issue of YSOD

Out of the clue i reached out to SLACK channel & Sitecore support for this behavior and they acknowledged that it is a bug currently in publishing profile & if you do not change anything and deploy, it copies all the DLLs & publishing profile target's are not working as expected.

Following is my OOTB platform.wpp.targets file which shipped with head repository 

https://github.com/sitecorelabs/xmcloud-foundation-head


 

Issue is with line no.16 where the " <Target Name="ExcludeSitecoreAssemblies" AfterTargets="Compile">" 

If you remove that line completely and make sure to restart your visual studio and do Clean & Publish, it will not only copy needed DLLs and everything will work

So finally my wpp file looks like below (Make sure to restart VS studio after the change)

As you can see in above image Target node is removed and now if i close my visual studio and do clean & build and publish again, it is only copying needed DLL and no more DLL hell issues 


Key take away & solution

1) Target tag which is available OOTB in wpp file works unpredictable

2) Publishing profile is misleading because, Sometime it works when we apply filter only when compilation happened, if no changes to the project it will publish everything. 

3) You have to remove Target tag from the wpp file & restart visual studio to make it work. 

NOTE: This was registered as a bug in Sitecore bug tracking system and reference number for this bug is 582640

I hope this will help other do not end up in the same issue as i did