开发者

ResXResourceWriter Chops off end of file

开发者 https://www.devze.com 2023-01-01 15:17 出处:网络
I\'m trying to create a .resx file from a dictionary of strings.Luckily the .Net framework has a ResXResourceWriter class.The only problem is that when I create the file using the code below, the last

I'm trying to create a .resx file from a dictionary of strings. Luckily the .Net framework has a ResXResourceWriter class. The only problem is that when I create the file using the code below, the last few lines of my generated resx file are missing. I checked my Dictionary and it contains all the string pairs that I expect.

public void ExportToResx(Dictionary<string,string> resourceDictionary, string fileName)
{
    var writer = new ResXResourceWriter(fileName);

    foreach (var resource in resourceDictionary)
    {
        writer.AddResource(resource.Key, resource.Value);
    }
}

Unfortunately, it is a little difficult to show the entire resx file since it has 2198 (should ha开发者_开发问答ve 2222) lines but here is the last little bit:

...
2195    <data name="LangAlign_ReportIssue" xml:space="preserve">
2196        <value>Report an Issue</value>
2197    </data>
2198    <data name="LangAlign_Return

BTW, notice that the file cuts off right at the end of that "n" in "LangAlign_Return". The string should read "LangAlign_ReturnToWorkspace". The file should also end at line 2222.


Try this:

public void ExportToResx(Dictionary<string,string> resourceDictionary, string fileName)
{
    using(var writer = new ResXResourceWriter(fileName))
    {
        foreach (var resource in resourceDictionary)
        {
            writer.AddResource(resource.Key, resource.Value);
        }
    }
}

You needed to call Dispose() on the writer. :)


Does "LangAlign_ReturnToWorkspace" actually say that, or is it "LangAlign_Return ToWorkspace"?

(With a space or perhaps a non-printing character between Return and ToWorkspace?)

Maybe that is causing the elememt name to be generated wrongly?

Just an idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消