string.Format exception Input string was not in a correct format

xeraphim

I received the following error from a string.Format(...) operation:

System.FormatException - Input string was not in a correct format.

I have a resource dictionary which contains an entry with a basic html page.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title of the document</title>

    <style>
        * { 
            margin: 0; 
            padding: 0; 
        }

        body { 
            font-family: 'Arial, Verdana', Fallback, sans-serif; 
            font-size: 14px;
        }

        table { 
            background-color: #eeeeee; 
            width: 100%; 
            padding: 10px;
            margin: 5px;
        }

        h1 {
            font-size: 16px;
            font-weight: bold;
            margin: 20px 0 10px 0;
        }
    </style>
</head>

<body>
    text<br />

    <table>
        <tr>
            <td>Text 1</td>
            <td>{0}</td>
        </tr>
        <tr>
            <td>Text 2</td>
            <td>{1}</td>
        </tr>
        <tr>
            <td>Text 3</td>
            <td>{2}</td>
        </tr>
        <tr>
            <td>Text 4</td>
            <td>{3}</td>
        </tr>
        <tr>
            <td>Text 5</td>
            <td>{4}</td>
        </tr>
        <tr>
            <td>Text 6</td>
            <td>{5}</td>
        </tr>
        <tr>
            <td>Text 7</td>
            <td>{6}</td>
        </tr>
    </table>
    <br />

    <h1>Header1</h1>

    <table>
        <tr>
            <td><a href="http://www.google.com">http://www.google.com</a></td>
        </tr>
        <tr>
            <td>Text 8: {7}</td>
        </tr>
    </table>
    <br />
</body>

The string.Format(...) operations looks like this:

var emailHtml = string.Format(
                    WebUtility.HtmlEncode(EmailResource.EmailTemplate),
                    "text1",
                    "text2",
                    "text3",
                    "text4",
                    "text5",
                    "text6",
                    "text7",
                    "text8");

Does anyone know what error I made? Isn't it possible to fill in the placeholders in the resource dictionary like this?

ISanych

You have a lot of curly braces which are not format specifiers, for example:

    { 
        margin: 0; 
        padding: 0; 
    }

Either you need to duplicate them:

    {{
        margin: 0; 
        padding: 0; 
    }}

Or using different formatting approach (like template engine).

Collected from the Internet

Please contact debug[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Input string was not in a correct format in double.Parse

From Dev

C# error : Input string was not in a correct format

From Dev

c# to sqlite input string not in correct format

From Dev

String 'Input string was not in a correct format' exception on JSON string

From Dev

Nullable Int Input string was not in a correct format

From Dev

Input string not in correct format to parse into DateTime

From Dev

"Input string was not in a correct format" error

From Dev

Razor DisplayFor of DateTime = Input string was not in a correct format

From Dev

Input string was not of the correct format

From Dev

Input string was not in a correct format in combobox

From Dev

String.Format throws 'Input string was not in a correct format' for Arabic Text

From Dev

Input string was not in a correct format exception in NuGet

From Dev

"Input string was not in a correct format."

From Dev

input string was not in the correct format error

From Dev

Error of input string was not in a correct format

From Dev

Input string was not in a correct format powershell

From Dev

Input string was not of the correct format

From Dev

{"Input string was not in a correct format."}

From Dev

"Input String was not in a correct format" - Why?

From Dev

Input String is not in the correct format

From Dev

Parsing String: Input string was not in a correct format. #

From Dev

Input string was not in a correct format in c#, int value is not in correct format

From Dev

Input string was not in a correct format

From Dev

Console (Input string was not in correct format)

From Dev

string.Format exception Input string was not in a correct format

From Dev

Input string was not in a correct format

From Dev

Input string was not in a correct format in a Formula

From Dev

{"Input string was not in a correct format."}

From Dev

Compare if input string is in correct format

Related Related

  1. 1

    Input string was not in a correct format in double.Parse

  2. 2

    C# error : Input string was not in a correct format

  3. 3

    c# to sqlite input string not in correct format

  4. 4

    String 'Input string was not in a correct format' exception on JSON string

  5. 5

    Nullable Int Input string was not in a correct format

  6. 6

    Input string not in correct format to parse into DateTime

  7. 7

    "Input string was not in a correct format" error

  8. 8

    Razor DisplayFor of DateTime = Input string was not in a correct format

  9. 9

    Input string was not of the correct format

  10. 10

    Input string was not in a correct format in combobox

  11. 11

    String.Format throws 'Input string was not in a correct format' for Arabic Text

  12. 12

    Input string was not in a correct format exception in NuGet

  13. 13

    "Input string was not in a correct format."

  14. 14

    input string was not in the correct format error

  15. 15

    Error of input string was not in a correct format

  16. 16

    Input string was not in a correct format powershell

  17. 17

    Input string was not of the correct format

  18. 18

    {"Input string was not in a correct format."}

  19. 19

    "Input String was not in a correct format" - Why?

  20. 20

    Input String is not in the correct format

  21. 21

    Parsing String: Input string was not in a correct format. #

  22. 22

    Input string was not in a correct format in c#, int value is not in correct format

  23. 23

    Input string was not in a correct format

  24. 24

    Console (Input string was not in correct format)

  25. 25

    string.Format exception Input string was not in a correct format

  26. 26

    Input string was not in a correct format

  27. 27

    Input string was not in a correct format in a Formula

  28. 28

    {"Input string was not in a correct format."}

  29. 29

    Compare if input string is in correct format

HotTag

Archive