How can I read global resource file in MVC controller, I am using this code and it is not working
Resources.BillingResource.Error;
returns the following exception
Could not load file or assembly 'Resources' or one of its dependencies. The system cannot find the file specified.
My application is MVC 4 and framework 4.5
Please advice
Is the resource file loaded in the same project or is on the different project. If its different project , you would have to add the reference to it.
Also check the namespace generated by the cs file of the resource file and reference that in your view or controller.
Related
I have an SPA application (lit-element, Google mwc and ASP.Net controllers) that is installed at several customers. There is a config.js file under wwwroot that contains some customer specific settings/URLs. This file is created at installation time manually. Problem is: everytime I update the app I have to restore this file from a backup because the update installation has replaced it with a template file.
I'd prefer to have the contents of this file in my appsettings.json file and generate config.js dynamically. In contrast the appsettings.json can then be placed in some external directory and passed to the web app via a command line parameter or environment variable.
Question is: how to intercept a request for config.js and dynamically create the file in memory?
I have a WinForms application that uses 3 .dll Application Extensions. Two of them come from the KBCsv csv file parser extension, and the third is the MySQL Data extension.
Currently these files are automatically stored in the project's Debug folder along with the application itself. When I move the application to an external location, I have to keep these extensions in the same folder as the application or I get an error like:
Could not load file or assembly 'KBCsv, Version....' or one of its dependencies. The system cannot find the file specified.
It would tidy up the desired folder that the application is to be located in if I could store these extensions in one folder, inside that folder. Any guidance as to how I could achieve this would be greatly appreciated.
I have deployed my web application in GlassFish server 3.0. When I execute it, I get an error: The system cannot find the file specified (MobileOntologyRev1.owl) , which is a file from which I read in my code (I haven't specified the absolute path for this file in my code, and simply refer it using the file name without any addtional path) . Where should this file be kept in order to access it? I have presently tried keeping it inside the WEB-INF/Classes folder and in the root dir of the application inside glassfish/domains/domain1/
Where should I place this file??
You may consider taking advantage of the FaceContext as mentioned below.
You can create a folder (repors) inside your WEB-INF for example.
String pathToFile=
FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports/MobileOntologyRev1.owl");
I have a resource file called Constants.resx which contains some strings. From the controller I am trying to access to a new string that I have just added to Constants.resx file but it is not recognized by the compiler (intellisense is not showning me the new string just added) and of course when I type it, an error is shown.
In the controller header I have added below line:
using Resources;
and to access to the new string just added I do the following:
Resources.Constants.NewString
I access to other strings in Constants.resx file using the same approach and no problem, they are recognized correctly, but not this new one.
Any ideas?
UPDATED:
My resource file for my mvc 4 app was added by selecting "Add > new item" from App_GlobalResources context menu and finally selecting "Resource file".
My resource files properties are:
Build action: Content
Copy to Output Directory: Do not copy
Custom Tool: GlobalResourceProxyGenerator
Custom Tool Namespace: (left blank)
Also I am using Visual Studio 2010 Express edition.
I can see the compiler is throwing a warning saying it cannot find the custom Tool 'GlobalResourceProxyGenerator' in the system.
You have to set the namespace of all the resource files as a common namespace like ViewResource. Then change the access modifier in the resource file as public. Now you can access those resource files.
Build action: Content
Copy to Output Directory: Do not copy
Custom Tool: GlobalResourceProxyGenerator
Custom Tool Namespace: ViewResource
Access Modifier : Public (In all resource Files)
I've got a 'Main app' and a 'Helper app' (sandboxed, if that matters) that share a private framework including some resources, nib files, sound files etc.
The framework gets called and used by both apps without issues. However from within in the Framework code I have a NSViewController that loads a nib file which is included in its resource folder. This seems to work as long as its called by the 'Main app'. Doing the same with the Helper app (a login item) however does not work and fails with an "Unable to find nib named" error.
The actual 'Framework' is copied to the Main app's 'Frameworks' directory and I use a #rpath in the helper app to find the framework: #executable_path/../../../../Frameworks
This setup seems to work just fine however at runtime it seems the frameworks code tries to find the named Resource under the helper app's Resource folder and not under the Framework's resource folder. Is there a setting or some flag that I can set in xcode to make the framework's always look under the exact path where the framework's executable/library is installed?
It seems the only solution is to copy the framework to the 'Helper' app as well. Resources otherwise do not get loaded if the framework was just a symbolic link to the actual framework placed inside the main app.
What you can do is making your Framework dynamic or shared like described here Dynamic Library Programming Topics
Though it is a bit of a complex process, but a very nice feature.
What else can help you?
Perhaps editing the Library Search Paths or the Framework Search Paths under your Build Settings in Xcode. there you can specify additional search paths to look for.
Even though, I would not copy the Framework to the Main app's dir. I would leave it in one place on your disk, add them to your project (Main and helper) and add the specified search path.
By the way: How is your framework implemented? Is it a folder, is it compiled, or is it only code files?