vivek
vivek

Reputation: 1605

Creating new theme in orchard with codegeneration module

I was following the documentation on this OrchardProject.net link. I opened have activated the CodeGeneration module and opened the command prompt at the root of the project (Orchard.Web) and write "bin/Orchard.exe" for running the commands. Till then everything is fine. Now when I try to run the following command, it gives me the below exception. The command is:

codegen theme mishrajiTheme /BasedOn:TheThemeMachine /CreateProject:true /IncludeInSolution:true

Below is the output of the command.

Creating Theme mishrajiTheme

Error executing command "codegen theme mishrajiTheme"

Specified argument was out of the range of valid values. Parameter name: startIndex

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: startIndex

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: startIndex] at System.String.Insert(Int32 startIndex, String value) at Orchard.CodeGeneration.Commands.CodeGenerationCommands.AddToSolution(TextWriter output, String projectName, String projectGuid, String containingFolder, String solutionFolderGuid) at Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateThemeFromTemplates(TextWriter output, String themeName, String baseTheme, String projectGuid, Boolean includeInSolution) at Orchard.CodeGeneration.Commands.CodeGenerationCommands.IntegrateTheme(String themeName, String baseTheme) at Orchard.CodeGeneration.Commands.CodeGenerationCommands.CreateTheme(String themeName)


What I am doing wrong here or It is a bug in Orchard code generation module. Please guide. I am using Orchard 1.10 version.

Upvotes: 1

Views: 555

Answers (2)

Pouya Samie
Pouya Samie

Reputation: 3723

I solved this problem by changing the CodeGenerationCommands Class in line 434 in Orchard 1.10. the line is :

 solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\r\n"),   projectReference);

to this :

 solutionText = solutionText.Insert(solutionText.LastIndexOf("EndProject\n"), projectReference);

i don't know why by \r\n can not found the final EndProject and by changing that to \n it works fine

Upvotes: 3

rtpHarry
rtpHarry

Reputation: 13125

The line of code in question that has failed is this:

solutionText = solutionText.Insert(solutionText
   .LastIndexOf("EndProject\r\n"),projectReference)
   .Replace("GlobalSection(ProjectConfigurationPlatforms) = postSolution\r\n", 
       projectConfiguationPlatforms);

If solutionText.LastIndexOf("EndProject\r\n") doesn't find anything it will return -1 - see the MSDN docs here.

It looks like that is then being passed to the string.Insert which is an invalid out of index.

The only thing that I can think is that your git client or however you got your hands on the orchard source has somehow changed the line endings in the file so it can't find the \r\n.

I'm guessing you are from the indian subcontinent, is your OS running a non-english language? I don't think that the .sln file localises fields like EndProject and I don't think Windows varies its newline character representation but something is going wrong here.

Workaround Solution

This is the very last thing that the codegen theme command does, it has created everything else and just failed to add your project into the Orchard.sln. To get moving right now you can just add it to your solution:

  1. In visual studio, open solution explorer window
  2. Right click on your Themes solution folder
  3. Click Add | Existing project
  4. Navigate to the folder and select your new theme

Potential Bug

It seems like there could be a bug here. Would you be willing to post your .sln file to me via email so I can investigate it further?

Upvotes: 1

Related Questions