I have a resource file named Res.en.resx in my Asp.Net Mvc 4 project.
In a view I'm trying to access its properties like this: #MvcApp.Resources.Res.Title but I'm getting the following error:
The type or namespace name 'Resources' does not exist in the namespace 'MvcApp' (are you missing an assembly reference?)
If I change resource name to Res.resx everything works fine.
Why is this happening?
I believe you need to have at least a file named xxx.resx which contain the translation for the default language of your application.
So if your main language is french and you would like to have an english version, you need:
xxx.resx file which contain the default language of your app.
xxx.en.resx file which contain the english version of your file.
Hope this help!
Related
In Xamarin, I have added the "universal-image-loader-1.9.2-with-sources.jar" as a file in the "Jars" folder of a binding project, I have then built the application but I am getting one error.
Here is the error:
Error CS0234: The type or namespace name 'DiskLruCache' does not exist
in the namespace
'Com.Nostra13.Universalimageloader.Cache.Disc.Impl.Ext' (are you
missing an assembly reference?)
Can I please have some help to get this code working?
Thanks in advance
You need to add the binding project as a reference in your Startup project.
To do so click on References directory in you solution tree and select the binding project in the "Projects" tab.
Good luck!
You need to create the Bindings Library project and then add this jar into the folder Jars.
For fixing error:
The type or namespace name 'DiskLruCache' does not exist in the namespace 'Com.Nostra13.Universalimageloader.Cache.Disc.Impl.Ext'
add to Transforms\Metadata.xml
<attr path="/api/package[#name='com.nostra13.universalimageloader.cache.disc.impl.ext']/class[#name='DiskLruCache']" name="visibility">public</attr>
Getting error in accessing resource file string from MVC controller(working file with views)
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "TempNameSpace.App_GlobalResources.Resource_EN_US.resources" was correctly embedded or linked into assembly "TempNameSpace" at compile time, or that all the satellite assemblies required are loadable and fully signed.
What I have already done
1. Resource file build action : from content to Embedded resource
Result : Publish does not include resource files in it.
2. Added new resource file with name Resource.resx
Result : Same error
Solution hierarchy
1. Solution contains 4 projects, two with resource files(Resource.resx and Resource_EN_US under App_GlobalResources folder)
2. Designer for Resource_EN_US contains correct namespace
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TempNameSpace.App_GlobalResources.Resource_EN_US", typeof(Resource_EN_US).Assembly);
In my projects I use a seperate project for resources. I have set all resource files Build Action property to Embedded Resource.
On the reference to the resources project, I have Copy Local set to True for the resources project. (Rightclick a reference and select Properties)
If you have your resource files inside your web project, I think that the property corresponding with Copy Local should be Copy to Output Directory (Also accessible via rightclick and Properties).
Edit:
I see that in your comment you said that you access the file as Resource.Resource_EN_US.WaterMarkEmail but this is not the right way to access the files. You should access them as one single file: Resources.Property.
My files are named as: Standard.resx, Standard.en.resx, Standard.no.resx and so on. To access them I can use Standard.Property. The resource files will mold toghether, but only if you give them valid names. If you can access all your resource files individually, then you have not used the correct naming convention.
I recommend implementing a ResourceHelper that uses the ResourceManager to access the property that you need.
I'm trying to read in the text (as a string) of an XML file from my Resources. The XML file is named MyXMLResourceFile.resx.
I tried using the C# way using
let myFile : string = Properties.Resources.MyXMLResourceFile
but it is giving me the error (under Properties):
The namespace or module 'Properties' is not defined.
I'm assuming I'm missing an open but have no idea what it would be.
Sorry, I'm still pretty new to F# coming from VB.
Additional information:
I made the resx file myself per this SO answer I then looked to see how others accessed it. In C# they did Properties.Resources.XXXX per this project I saw you could use ResourceManager but didn't see any method to read the whole file directly into a string.
The namespace or module 'Properties' is not defined.
That's because the namespace Properties is not defined. You probably brought the resx file from another project. Open the associated .Designer file, if it doesn't appear in the F# project, open it up in the original project. You will see a namespace with and a bunch of C# code, assuming the original project was in C#. The namespace of this file has to be the same namespace of the project where you are trying to call it.
But, since this is C# code, it won't run on a F# project. You have two choices: use a code generator to generate the associated .Designer class in F# code with the Properties namespace, (I don't know if such generator exists); or pre-compile the resx in the original project and reference it as a dll from your F# project, then you can access it with ResourceManager.
So I've recently started with ASP.NET MVC 4. I'm using the razor engine.
My question is concerning the view files, with suffix cshtml. It seems to me that these are precompiled into *.cs files by razor which in turn are then compiled into MSIL. (A pattern that is familiar from my days as a JSP developer.) One reason why I am making this assumption is that if I enter some invalid c# code into the cshtml file I get a compilation error displayed like this:
Line 34: public class _Page_Views_BaseDataAdmin_Index_cshtml : ...
And line 34 is not indicative of where the error is in the cshtml file, just as the class _Page_Views_BaseDataAdmin_Index_cshtml seems to refer to a regular .net class not the view file.
So my question is: Where do I find the cs file? Specifically, in the example above, "_Page_Views_BaseDataAdmin_Index_cshtml.cs"? Maybe I need to add some config to tell MVC to keep this .cs file on disk, if so, how do I do this?
Thanks!
A quick tip to find the generated files is to add this to your .cshtml file.
This will show you immediately the full path
<div>This file is compiled to #this.GetType().Assembly.CodeBase</div>
You can find the compiled views in your Temporary ASP.NET Files folder.
First find the .compiled file that corresponds to your view (ex: home.cshtml):
home.cshtml.a8d08dba.compiled
This file contains the assembly name: assembly="App_Web_hkc53urb"
Your .cs file will be the assembly name concatenated with a number: App_Web_hkc53urb.1.cs
An easier approach might be to use Windows search for your view name in the temp ASP.NET directory.
I have set up a new MVC 4 web application. I am currently running source code anaylsis against the project and getting the following error:
CA1707 Identifiers should not contain underscores
The reason for this is because of the namespace "App_Start" due to the App_Start folder name. Are there any issues with renaming the folder to "AppStart"? This will mean all my rules are passed.
I would suppress that rule for that particular namespace rather than rename it. Create a GlobalSuppressions.cs file in your web project root, and add this:
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Naming",
"CA1707:IdentifiersShouldNotContainUnderscores",
Scope = "namespace",
Target = "<namespace>.App_Start",
Justification = "This is an infrastructure namespace")]