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.
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
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):
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;