I am using a custom theme and load it as .tssp file in my Program.cs at the moment (which works):
ThemeResolutionService.LoadPackageFile("data\\myThemeName.tssp");
But instead I want to load the .tssp file as embedded resource. Therefore I added the file as resource file under Resources.resx and put the following method in my Program.cs:
ThemeResolutionService.LoadPackageResource("myProject.Properties.Resources.myThemeName");
But the following error occurs:
Specified resource does not exist in the provided assembly.
The path within quotation marks should be correct as the IDE finds it when I remove the quotation marks. I also use different images as embedded resource under the same ressource path which works.
Is this Telerik method bugged or am I doing something wrong?
The ThemeResolutionService class exposes two static methods that allow you to load a theme package:
LoadPackageResource: This method loads a theme package file that is contained in the project as an EmbeddedResource. This is the preferable method for loading a theme package since the resource path to the package is not changed when the application is deployed. The path construction is DefaultProjectNamespace.ThemeFolder.ThemePackageFile. The ThemeFolder part should only be used if the package is contained in a folder under the main project directory and if the project programming language is C#. In VB.NET project you do not need to include ThemeFolder part even if the package file is contained in a folder.
ThemeResolutionService.LoadPackageResource("SamplesCS.CustomTheme.tssp");
public RadForm1()
{
InitializeComponent();
ThemeResolutionService.LoadPackageResource("CustomThemeResourcePackage.Resources.FluentDarkModified.tssp");
ThemeResolutionService.ApplicationThemeName = "FluentDarkModified";
}
And the result:
LoadPackageFile: This method loads a file from a specified directory on the system. Depending on how the directory is defined (full or relative), the path to the package may change when the application is deployed on another machine.
ThemeResolutionService.LoadPackageFile(#"C:\CustomTheme.tssp");
Related
If I include a .bin.gz file in a DLL as an embedded resource, it doesn't show up in the Assembly.GetManifestResourceNames() list, and cannot be loaded with Assembly.GetManifestResourceStream(). If I rename the same file to anything else, it does show up.
The .bin.gz file shows up in .csproj. I'm building a .NET Core 2.2 class library.
What's going on? Is there some kind of filter by file type that prevents certain types from being embedded?
EDIT: On further inspection. It appears that the .bin.gz resources are placed in a different .dll named [AssemblyName].resources.dll, which is placed in a "bin" folder next to the [AssemblyName].dll. Why is this and why does this not happen with other files?
I have a C# application that is being internationalized. I want to keep all of my language resource directories (en-US, es-SP, etc...) in a single directory called "languages" within the installation directory, so that the file path would be something like C:\application\
languages\en-US\resource.dll for each compiled resource file.
Unfortunately, the .dll that references the language resource file is in the C:\application\mainprogram.dll location. What do I need to set in Visual Studio so that mainprogram.dll can correctly access all of my language resource dll files?
Also of note is that the language resource files work fine if all of their folders are on the same level as the mainprogram.dll file.
You can specify additional private paths using the Probing Element in your configuration.
Alternatively and probably more than you would need:
You can hook in to the AppDomains Assembly resolve event which gets called every time it fails to find an assembly via standard probing.
I'm trying to add globalization support to my C# application.
According to MSDN, there should be one embedded resource file for neutral culture and satellite DLLs with resource files for other cultures.
I've created 2 satellite DLLs without any problems and got my app to automatically load right one using ResourceManager. But I can't embed default neutral culture resource file into my executable. When I remove all satellite DLLs or set culture to some culture I don't have satellite DLL for, I get exception "Could not find any resources appropriate for the specified culture or the neutral culture." when application attempts to create ResourceManager.
It looks like VS 2008 does not include my .resource file into main assembly. I've tried different ways to get resource file embedded: compiling it by resgen.exe from text file and adding it to the project; changing its name to add second .resources extension; creating .resx file with same name; etc. And I still don't see the way to get resource file embedded and used by ResourceManager - I'm having same exception.
What is the right way to add default neutral culture resource file to application in VS 2008 ?
Ok, I've solved this problem by little 'hack'.
I've compiled resource file using resgen.exe, as described in MSDN, then added it to the project, renamed it to "resources" and changed build action from "None" to "Embedded resource".
Looks like VS 2008 adds "." as prefix to resource file name. So if u will name your resource file ".resources" it won't work cuz actually VS will name it "..resources".
in .Net the resource files are using the .resx extension. To have it 'embedded' in your project, make sure the "Custom Tool" in the properties page of the .resx file is using the "ResXCodeGenerator"
Hope this helps,
I have an image that is used in some PDF files that my C# application generates. I know how to reference the image file when it is located in my workspace, but when I compile the program, I don't see the image anywhere in the compiled directory.
Can someone tell me what happened to that file, or do I have to manually package the file along with my program when I send the program to the users? I added the image to the workspace by drag-drop to the resource directory of one of my namespaces.
Check the file's properties in Visual Studio. Have you set the CopyToOutputDirectory property to something besides Do not copy?
Hmm... I'm not sure about the whole drag-drop business, but if it's all working the resource will have been embedded into your assembly.
I suggest you have a look with Reflector - you can see the resources embedded within assemblies using that.
Have a look at the build properties for the item in Solution Explorer - in particular, if the build action is Embedded Resource then it will indeed be built into the assembly.
I have added multi-language using the short article below.
When you add for example German language you will have these files:
formMain.resx
formMain.de-DE.resx
formMain.Designer.cs
formMain.cs
In first file you will have resources for neutral language, like strings, images, ..
So now you need to add also resources for strings used in code. Add a new resource file and name it formMain.Strings.resx
Then i will enter name, value pair for every string that should be translated. When you add resource file then it is automatically typed because another file with name formMain.Strings.Designer.cs is automatically regenerated on every close of resx designer.
Add another resource with name formMain.Strings.de-DE.resx. Add the same Name key's from previous resource, and just change the Value with coresponding german words. Now to access created resource from the source it will be like this.
MessageBox.Show(formMain_Strings.SameStringName);
However, I have changed my to Thai language. Everything works fine when I run my app in VS.
However, as soon as I add a setup project and install on the clients machine it won't change the language to Thai and just keeps to the default language.
So I have added the resource files and the th-TH dll to the project setup. And I still get the same problem.
Packaging file 'Lang.Strings.resx'...
Packaging file 'MultiLanguage.resources.dll'...
Packaging file 'MultiLanguage.exe'...
Packaging file 'Lang.Strings.th-TH.resx'...
As everything works fine when running in visual studio. Is there something I need to do to get it to run once its been installed. All the properties for each of the file I have keep the default.
Many thanks,
=========
static void Main()
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo("th-TH");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
I found the answer
Click the Setup Project in Solution Explorer and then click Add\Project Output\ . From dialog select the project for which you want to include localization (satelite) assemblies and then select Localized resources.
After the installation in the folder that I install to, I have the th-TH folder which includes the satellite assembly.
Thanks,
Try adding in this at the app's startup (if it's not there):
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;
Here is a short article discussing some of the options of how to make this work, and options for selecting the locale at runtime.
Edit after comments:
Make sure your satellite assembly is in the appropriate place, and built correctly. From that article I referenced:
"When .NET runtime starts an application it looks for a possible satellite assembly file. A satellite assembly file is a resource only assembly file that has .resources.dll extension instead of .exe ir .dll (if the main assembly is a library). Satellite assembly files always locate on a language specific sub directory of the applciation's main directory. If application file is Converter.exe then the Japanese satellite assembly file is ja\Converter.resources.dll."
There are a few things that you should check here. Check the name of the assembly. Also, make sure it's in the proper location. In your case, it should be in a th-TH subdirectory with the appropriate name under your executable. If it's there, it should be found and used properly.
Here is another good source of information about this topic.