1

I keep getting a culture error and I'm unable to resolve it. I've tried to iterate on the issue, previously raised a question that was closed and implemented various solutions without any success. Details of all tested solutions are mentioned at the end of the question. Here are my two files:

First file (main code):

using Properties;
using System;
using System.IO;

namespace malt
{
    class Programs
    {
        static void Main(string[] args)
        {
            byte[] med = Properties.Resources.med;
            Console.WriteLine(med);
        }
    }
}

Second file (Resources.cs in the same folder as Resources.resx):

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Resources;
using System.Runtime.CompilerServices;


namespace Properties
{
  internal sealed class Resources
  {
    private static ResourceManager resourceMan;
    public static CultureInfo resourceCulture = CultureInfo.InvariantCulture;


    internal Resources()
    {
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    internal static ResourceManager ResourceManager
    {
      get
      {
        if (Properties.Resources.resourceMan == null)
          Properties.Resources.resourceMan = new ResourceManager("Properties.Resources", typeof (Properties.Resources).Assembly);
        return Properties.Resources.resourceMan;
      }
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    internal static CultureInfo Culture
    {
      get => Properties.Resources.resourceCulture;
      set => Properties.Resources.resourceCulture = value;
    }

    internal static byte[] med => (byte[]) Properties.Resources.ResourceManager.GetObject(nameof (med), CultureInfo.InvariantCulture);
  }
}

Full error:

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure that "Properties.Resources.resources" was correctly embedded or linked into assembly "madt" at compile time, or that all the satellite assemblies required are loadable and fully signed.


Note I asked this question before, but although the address it directed was not a solution, it closed the question and did not reopen it even though I edited it. That's why I asked again :)

List of things I've tried:

  • Before saying this link is an answer and closing the question Could not find any resources appropriate for the specified culture or the neutral culture:

  • The Compilation Action property of my .resx file is Embedded and still not works

  • Both of files are not including any special chars

  • I've played too much time with "CultureInfo.InvariantCulture" in Resources.cs's internal static byte[] med => (byte[]) Properties.Resources.ResourceManager.GetObject(nameof (medus1), CultureInfo.InvariantCulture); line

  • I've also tried the answers to the previously asked questions but it didn't work

  • I don't have a function like this in my code ProblemAssembly.Support. My problem is in internal static byte[] med => (byte[]) Properties.Resources.ResourceManager.GetObject(nameof (med), CultureInfo.InvariantCulture); line. If you can adapt this please let me know

  • My resx file's build action option is already Embedded Resource

  • Already I don't have Properties/Resources.designer.cs file

  • My resx file is already included in project

  • I don't use .NET Core 3.0

  • Tried to change CultureInfo type to public, private, internal but no one has been worked

  • Tried to change project name

  • If I use try catch for escaping from this error, my code will not work and nothing will be different

Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
  • Main file name is different by project name and also not program.cs too – Katolik Mamut Apr 22 '23 at 15:18
  • I have added an answer to this, but I'm still not certain what is the actual question - whether it is just "how to use resources in the application" or something more delicate like "using resource with selected culture only". So I've updated also your question - how it made the most sense. If you don't agree on that, please update it so it reflects actual state. :) And if you find my answer helping you with the issue, it would be great to "accept it as an answer" and/or "vote it up". Thanks. – Tatranskymedved Apr 22 '23 at 15:44

1 Answers1

0

I think that you are missing a point about "how this resource file should work". Developer is not ment to create and write this Resources.cs file himself, instead it should be automatically generated whenever the actual resource change (resx file).

That means: If you add new line/new file into Resource1.resx -> Visual Studio (or any other IDE) will invoke regeneration of that Resources1.Designer.cs by using the generator tool specified in the properties of the file. And this generator tool will modify existing Resources1.Designer.cs and append new C# code, that can be later used in the application.

I'm attaching screenshot about how it looks in Solution explorer (notice that the Resource1.Designer.cs is hidden under the Resource1.resx file, it must be expanded to be seen) + details of settings for resx file (it is marked as Embedded resource and have ResXFileCodeGenerator as a generator):

Resources file

To obtain the resources from the file, just grab it directly via generated code:

// The format for accessing is <nameOfFile>.<nameOfResourceWithinFile>
var myResource = Resource1.med;
Tatranskymedved
  • 4,194
  • 3
  • 21
  • 47
  • **Comments have been [moved to chat](https://chat.stackoverflow.com/rooms/253291/discussion-on-answer-by-tatranskymedved-creating-own-code-for-resource-is-throwi); please do not continue the discussion here.** Before posting a comment below this one, please review the [purposes of comments](/help/privileges/comment). Comments that do not request clarification or suggest improvements usually belong as an [answer](/help/how-to-answer), on [meta], or in [chat]. Comments continuing discussion may be removed. – Samuel Liew Apr 23 '23 at 06:58