0

I have an .resx file that contains a few strings. Its path in the Solutions Explorer is:

Resources\main_resource.resx

I am trying to delete and re-create it programmatically using the ResXResourceWriter class.

using (var writer = new ResXResourceWriter(@"../Resources/main_resource.resx"))
writer.AddResource("new string", "new value");

This doesn't work. I get the following error:

Could not find a part of the path 'C:\Users\Joshua\Documents\Visual Studio 2019\MyProject\MyProject\bin\Resources\main_resources.resx
NewYorker
  • 73
  • 4
  • https://stackoverflow.com/questions/13218777/can-i-edit-resource-file-at-runtime – Legacy Code Jul 18 '20 at 10:29
  • Have you not marked the resx file properties as content copy if newer? What that seems to imply is when you build you've not got the file copied into your bin. As an aside. Personally, i would use an uncompiled resource dictionary and make strings wpf resources rather than use a resx. Xamlreader.load it into a resource dictionary and merge or just merge the loose file directly. – Andy Jul 18 '20 at 10:30
  • @LegacyCode I have already seen that answer but it doesn't address my issue. – NewYorker Jul 18 '20 at 10:55
  • @Andy Changing the Build Action to Content displays an entirely new error during Initialization. System.Windows.Markup.XamlParseException: ''Provide value on 'System.Windows.Markup.StaticExtension' threw an exception. – NewYorker Jul 18 '20 at 10:57
  • You fixed one problem but that's not your only one. – Andy Jul 18 '20 at 12:07

1 Answers1

0

I am pretty sure you only need to go one more step back, by that I mean you need "../" twice. Please let me know if it works :)

var writer = new ResXResourceWriter(@"../../Resources/main_resource.resx")
Nicholas
  • 87
  • 9