0

I have a resource file named Test.resx and I am trying to add Name&Value to the resource file dynamically using C# code like below and my code works fine but when I try to open the file or read the file it says the below error.

Error: Value does not fall within the expected range

my c# Code,

  //path: .../Test.resx
  var path = Path.Combine(_env.ContentRootPath, PlatformServiceConstants.FieldResources + "Test"+ PlatformServiceConstants.ResourcesExtensions);

        ResourceWriter resourceWriter = new ResourceWriter(path);

        resourceWriter.AddResource("Name", "Name");
        resourceWriter.AddResource("Age", "Alter");
        resourceWriter.Close();

Is there any error in the code or approach? Where I did go wrong?.

Md Aslam
  • 1,228
  • 8
  • 27
  • 61
  • You must have a schema and Age expects an integer. – jdweng May 13 '20 at 09:39
  • What? Age means not an integer here. In the Resource file, everything is key & value pair which both are in string format. And Why I should have schema while AddResource method allows passing the Name & Value (key&value) directly. – Md Aslam May 14 '20 at 09:09
  • "Value does not fall within the expected range"?????????? – jdweng May 14 '20 at 09:27
  • That's mean the value is not added properly to the resource file, it's not mean data type problem. If it's a data type problem, then I could have fixed this within a minute. Did you check What the .resx file contains? By default, three columns will be there such that is 1. Name 2. Value 3. Comments. These 3 column fields are accepting the string type so data can be either alphabets or numbers. – Md Aslam May 14 '20 at 09:38
  • So are you adding a duplicate key? The values can still be determined from a schema. – jdweng May 14 '20 at 09:40
  • No, I am not adding any duplicate key. – Md Aslam May 14 '20 at 15:38
  • I came to this post having a completely unrelated problem but one that produced the same error message. This message is somehow **misleading** because the actual error may not be related to any **"range"** at all. This is just the default message issued by `throw new ArgumentException()` ... and a good reason never to use ourselves this parameterless constructor. Unfortunately it seems it is sometimes used in standard .Net classes. – avat Apr 18 '23 at 07:52

0 Answers0