0

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Unterminated string literal. Strings that start with a quotation mark (") must be terminated before the end of the line. However, strings that start with @ and a quotation mark (@") can span multiple lines. Closing HTML tags within a string literal may trigger this error message.

The below code snippet gives the above error 3rd last line. Can someone please help me out. It will be great help.

 objData += $@"annotation: {{
                titleText: ""{ann.titleText}"",
                left: {{
                    type: ""{ann.Left_type}"",
                    text: ""{ann.Left_text}"",
                    updatedAt:""{ann.Left_image_UpdatedAt.ToString().Split(' ')[0]}"",
                    updatedBy:""{ann.Left_image_UpdatedById}"",
                    image: """ + Url.Action("GetFile", "home", new { filename = ann.Left_imageURL }) + $@""",
                    translateDate: ""{ann.Left_trans_UpdatedAt.ToString().Split(' ')[0]}"",
                    translateUser: ""{ann.Left_trans_UpdatedById}"",
                    imagetranslateFileURL:"""+Url.Action("GetFile", "home", new { filename = ann.Left_imagetranslateFileURL })+$@""",
                }},
                right: {{
                    type: ""{ann.Right_type}"",
                    text: ""{ann.Right_text}"",
                    updatedAt:""{ann.Right_image_UpdatedAt.ToString().Split(' ')[0]}"",
                    updatedBy:""{ann.Right_image_UpdatedById}"",
                    image: """ + Url.Action("GetFile", "home", new { filename = ann.Right_imageURL }) + $@""",
                    translateDate: ""{ann.Right_trans_UpdatedAt.ToString().Split(' ')[0]}"",
                    translateUser: ""{ann.Right_trans_UpdatedById}"",
                    imagetranslateFileURL: ""{ Url.Action("GetFile" , "home", new { filename = ann.Right_imagetranslateFileURL })}"" ,
               }} 
    }}";
  • As a side note, your dates probably (if I understand what you're doing) can be reduced to (for example) `{ann.Left_image_UpdatedAt:d}`. The "d" format gives the [date in short form](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings#table-of-format-specifiers). That will eliminate the ceremony of splitting strings and the extra allocations. – madreflection Dec 10 '21 at 00:38
  • @madreflectionI'm sorry to not have included the error. I have updated it. Really thanks for this date conversion hack. Short and much more readable :) – Harshit Aggarwal Dec 10 '21 at 00:55
  • You're welcome, but "hack" implies that it's something non-standard that just happens to work. Rather, that's a very standard way of formatting dates. It's there for exactly that purpose. – madreflection Dec 10 '21 at 00:58
  • It might be off the topic but I would like to know more about this conversion. Are there conversions other than date exist? If yes then can you please guide me. What is this method called as? – Harshit Aggarwal Dec 10 '21 at 01:02
  • There certainly are, but it's called **"formatting"**, not conversion. Using the right term will help you find information. You need to do some Googling for ".net formatting". It'll give you results for both *standard* and *custom* formats for `DateTime`, `TimeSpan`, all the numeric types, and various others. It's all been in the BCL since the beginning so there's tons of information out there. – madreflection Dec 10 '21 at 01:06
  • *"What is this method called as?"* ("as" is not grammatically correct there, by the way; lose it). Custom and stardard formats can be used when a type has a `ToString` method that takes a `string? format` parameter (and there might also be an `IFormatProvider` parameter as well). The ":d" in the interpolation placeholder uses the part after the `:` as the `format` argument in a call to one of those `ToString` overloads. – madreflection Dec 10 '21 at 01:10
  • Anyway, I don't see the syntax error in your code. Strip it down and build it back up until you introduce the error again. – madreflection Dec 10 '21 at 01:12
  • Is this a c# syntax error? Or an error somewhere else while trying to parse your output? Is this supposed to be json? Is the problem that your "json" strings aren't escaped? IMHO replace the whole thing with `JsonSerializer.Serialize`. – Jeremy Lakeman Dec 10 '21 at 03:16
  • @madreflection Its a compile time error. imagetranslateFileURL: """+Url.Action("GetFile" , "home", new { filename = ann.Right_imagetranslateFileURL })+$@""" , This does not give error – Harshit Aggarwal Dec 10 '21 at 04:47
  • @JeremyLakeman What is the "whole thing" that you are refering to? – Harshit Aggarwal Dec 10 '21 at 04:50
  • *"Its a compile time error"* and then *"This does not give error"* ? - these are contradictory statements; the former is consistent with the post, a parser error. Reduce the string until you don't get the error anymore. – madreflection Dec 10 '21 at 05:10
  • I'm sorry but I guess the way I wrote is difficult to understand. `imagetranslateFileURL: """+Url.Action("GetFile" , "home", new { filename = ann.Right_imagetranslateFileURL })+$@""" ,` I meant if I change to this, then it works perfectly. – Harshit Aggarwal Dec 10 '21 at 05:14

0 Answers0