I have been searching for a long time but the topic seems to be quite special. I didn't come up with anything. Maybe the specialists arounf here can help me.
I run a Windows Service which accesses some databases and does some calculation. If something fails, then that will result in an entry in a log file.
My wish is to lacalize these entries.
This worked fine with every project so far except for this Windows Service.
I use the resource manager and localized resources files.
During runtime the CultureInfo is changed by:
Thread.CurrentThread.CurrentUICulture = new CultureInfo(this.language);
where language is a value read from the config file.
The changes are veryfied at the next line:
LogService.WriteEntry(CultureInfo.CurrentUICulture.Name, EventLogEntryType.Information);
This works and returns the correct CultureInfo.
The resources files are named correctly but still, the localized file (in that case "de") can't be accessed and the default (english) file is used.
I added the resource files to the project output in the setup project.
Edit:
In other Projects, the following worked fine, but not for the Windows Service:
ResourceManager locRM = new ResourceManager("WindowsService.ResWindowsService", Assembly.GetExecutingAssembly());
It seems the Windows Service just can't find the satellite assembly and then falls back to the neutral resource file which seems to be within the Windows Service exe file.
Has anyone an idea how i can get the Windows Service to find the satellite assembly.
Edit 2: THE SOLUTION
A dear colleague helped.
I strongly named the satellite assembly and registered it in the GAC. That was the solution. Now the Windows Service can access it.
Detailed steps:
In the setup project's file system editor: Add special folder -> Global assembly cache folder.
Add file -> I added the resource file here
Then under Project Properties -> Signing mark "Sign the Assembly" and create a new key file.
That's it.
Thanks,
Nils
Related
I have some forms I have created in a local directory D:\PsToolBox. I added them to the repository, now when I inherit from them the IDE adds the Base form to the project's file, no problem. I get :
PsListView in 'D:\PsToolbox\Source\View\PsListView.pas' {frmPsList},
Unit4 in 'Unit4.pas' {frmPsList4};
However I code on 2 different computers through version control on BitBucket. The PsToolBox directory is in different locations so I need a common path in the project file.
I tried creating an environment variable PsToolBox with the path D:\ToolBox on the first machine and then editing the dpr file path of the base form to
PsListView in '${PsToolbox}\Source\View\PsListView.pas' {frmPsList},
This compiles and runs, however if I try to edit my form I get an error that the system cannot find the file. Also moving between projects in the group triggers the error as well. Closing and reopen same result.
I tried adding the environment path
$(PsToolbox)\Source\View
to both the Tools/Options/Langauge/Delphi/Library Windows32 platform, as well as the project search path. No Joy.
What am I missing? Is this even possible?
So this was quite a hilarious error and was quite difficult to trace, so I'm going to chuck everything on here in case it happens to anyone else;
While working on a website in production, its name changed. I noticed that the IISExpress instance displayed not only the new name, but a '\' and the old name as three separate instances.
As I was attempting to add log4net to the project, I attempted to use this line in the web.config:
<log4net configSource="log4net.config" />
Which caused the following error on app run:
the configSource file '[file]' is also used in a parent, this is not allowed.
the configSource file is also used in a parent, this is not allowed.
This was perplexing as I had not used this source anywhere else, and no matter what file I changed it to, I got the same error.
log4Net worked fine when I defined it entirely within my web.config, but that's not what I wanted, so I investigated further. Interestingly, a colleague who'd just been brought onto the project could run the app fine with the separated config, but I and another dev who'd been working on this project for a while could not.
How can I and another colleague with exactly the same setup have a failing app with the same config as someone with a fresh checkout have it work fine?
The web.config file is "composed" when it is read by the application by scanning the file system from the current directory up to the drive root and by looking in a number of pre-defined places (such as the location of the Machine.Config and the default ASP.NET config.) If you're using Virtual Directories on the same website in IIS, things can turn even more interesting.
Any of these files can define configuration sections and can possibly externalize the configuration, and thus cause the error message you're seeing.
The following doc on MSDN outlines exactly how the configuration is being parsed and composed:
https://msdn.microsoft.com/en-us/library/ms178685.aspx
It turned out to be that IISExpress had saved the previous settings in a .vs folder at solution's root level, and all three of those instances were using the same config, and looking for the same file, hence the error.
The solution was as follows:
In the web-app's project, reset the web properties to look at the root site (\ instead of \newname\)
Trash the entire .vs directory
Restart Visual Studio and Reload the project.
For different versions of VS, the .vs folder is in different locations on your machine.
I am trying to run a crystal report from my web application which was built using ASP.NET 4.0 and Visual Studio 2010. I have installed the following from the SAP site (http://www.businessobjects.com/jump/xi/crvs2010/us2_default.asp)
1) SAP Crystal Reports, version for Visual Studio 2010 - Standard EXE installation package which installs the software into the Visual Studio IDE.
2) SAP Crystal Reports runtime engine for .NET Framework 4 (64-bit)
I have a page called Reports.aspx in which I have a crystal report viewer control
<CR:CrystalReportViewer ID="rptViewer" runat="server" AutoDataBind="true" />
In the Reports.aspx.cs file I have the following code:
protected override void OnPreRender(EventArgs e)
{
ReportDocument report = new ReportDocument();
var path = Server.MapPath("Reports/Sample.rpt");
report.Load(path);
report.SetDatabaseLogon("username", "password", "servername", "databasename");
rptViewer.ReportSource = report;
}
On the report.Load(path) line I get the following error:
Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack.
How can I fix this?
I also got into the same problem my problem was report path was not valid, May be you have same problem , check Server.MapPath("Reports/Sample.rpt") returning valid path ?
make sure the report is in app_code folder
initialize a new instance of it instead of initializing a reportdocument and loading the report in it.
Sample report = new Sample();
this worked for me
You will need to modify two properties in the .rpt files:
Build Action is set to "Embedded Resource" by default. Change it to "Content".
Copy to Output is set to "Do not copy" by default. Change it to "Copy always".
Rebuild, Build deployment package and Publish. Done!
NOTE: Below, the term "WebSite" refers to actual web site nodes in IIS, NOT a virtual directory within a web site.
Problem Root Cause: There is no "aspnet_client" folder accessible by the application.
This can happen for several reasons:
Since the SAP CR installer appears to install the aspnet_client folder in the ...\inetpub\wwwroot\ folder, if your Web Site physical path is NOT ...\inetpub\wwwroot, your application will not have access to the aspnet_client folder.
If the aspnet_client folder was moved or deleted from to the top level of your web site's physical path, your IIS application will not have access to the folder.
Problem Solution (For Windows Server 2008 R2)
Go to the IIS manager on your server
Expand the tree view node for the WebSite running your application
Look at the level immediately under the web site node and ensure you see a "aspnet_client" folder.
If you do see the folder, then perhaps this root cause is not the cause of your problem.
If you do NOT see the folder, search the server's hard drive for it and COPY it to the Web Site's Physical path.
Right mouse button click on the Web Site node and click Refresh from the popup Menu
You should now see the aspnet_client folder at the level directly under your web site node and the reports in the application should work.
I ran into this when I converted a web site to a web application. The report would run fine on my dev machine, but not on the server. Then I realized the rpt file was missing on the server!
By default the report files were considered embedded resources and were not copied when the web application was published. I just changed them individually, republished the site, and all was well again.
I have also had a report load failure if I have mistakenly left the report file open in crystal reports designer.
This error is a real treat, and seems to have many possible antecedents. Fortunately I only wasted a day on my particular variation:
ReportDocument.Load() also makes a local temp copy. (This may only be in the case of a load from a network drive location, I didn't test this in the case of a local load.)
If the user context under which the load occurs does not have authority to create the temp file locally, Load will fail with the same very unhelpful error.
Also, I ended up diagnosing this with Process Monitor. It may be helpful for you as well.
Please make sure your report rpt files are in their original folder. I got the same error first, after I "published" my MVC web site to IIS. I didn't realize that "Publish" didn't put rpt files in the package.
Re-install the "Crystal report engine" to the server
Build Action set to "Content".
It perfectly worked for me..!
I'm having some trouble merging the localization satellite assemblies into the plugin DLL for CRM2011.
Either that, or I don't know how to use the merged resources afterwards.
I create a few plugins and create a basic resource file (default - English) and one for a specific culture (at the time of writing it's for Polish localizations, but later I'll need to add French as well).
I make sure not to sign the assembly itself, as ILMerge will sign the finished assembly itself.
This is the command I use to merge the extra satellite assembly:
ilmerge /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /log:log.txt /keyfile:KeyFile.snk /out:Plugins.dll DynamicsCRM2011.Plugins.dll pl-PL\DynamicsCRM2011.Plugins.resources.dll
As you can see, the plugins are in .NET 4.0 and I've got the required .config file for ILMerge to use the required assemblies for merging.
The generated file appears fine, I can register it with CRM plugin-registrator, add new steps and so forth.
However, it will always use the default language. I've tried changing the System.Threading.Thread.CurrentThread.UICulture, but this didn't help. When I created a ResourceManager class and used GetString("ErrorMessage", new System.Globalization.CultureInfo("pl-PL")), I got an Exception that the specified ResourceManager doesn't know what to do with the specified culture.
I know of this question here. However, the posted solution seems to be an old one. The generated resource .cs files do not use a ComponentResourceManager. Also, parts of the code posted there have been marked as deprecated.
I'm not really sure what I'm am to do now, or how to further debug this, as I have very little experience when it comes to working with assemblies themselves. Please, help me get those satellite assemblies under control.
Update:
I've been working with sandbox plugins for a while now, and thus I no longer have access to things such as CurrentCulture (or at least I cannot change such things). I've tried tackling this problem once more: I've created a simple plugin which is fired when a new Account is saved. Nothing fancy. Here's the actual plugin code:
ResourceManager rm = new ResourceManager(typeof(Properties.Resources));
var s = rm.GetString("ErrorAlreadyPosted", new System.Globalization.CultureInfo("pl-PL"));
throw new InvalidPluginExecutionException(s);
The code no longer throws an exception about not being able to find the specified culture... also the code obviously throws an exception at the end, but the important thing is WHAT the exception message is. I'd expect it to be in Polish.
Alas, it is not. The string returned by GetString is still in English.
The command I used for ILmerge is the same as before, but with the /lib parameter specified so that I don't have to copy all the CRM SDK dlls...
Apparently it is not possible to read resources from with the context of a Plugin.
Read up on MSDN: http://msdn.microsoft.com/en-us/library/hh670609.aspx#BKMK_UseXMLWebResourcesAsLanguageResources
Quote: When a plug-in requires localized text, you can use an XML web resource to store the localized strings so the plug-in can access them when needed. The structure of the XML is your option, but you may want to follow the structure used by ASP.NET Resource (.resx) files to create separate XML web resources for each language. For example, the following is an XML web resource named localizedString.en_US that follows the pattern used by .resx files.
This is all I know so far - have yet to build my own solution for localization of a crm plugin.
If you use a reflector tool to look at the generated assembly, do you see your resource(s) embedded correctly? You may be experiencing the bug as outlined in the link you posted.
Try setting Thread.CurrentThread.CurrentUICulture and\or Thread.CurrentThread.CurrentCulture.
Also try hooking into the AppDomain.CurrentDomain.AssemblyLoad and\or AppDomain.CurrentDomain.AssemblyResolve to debug which assemblies are being attempted to load and from where. You might need to customize their behavior so that instead of loading an external assembly to load an internal resource instead.
You can try embedding project references as resources instead of using ilmerge as well.
See this: http://bartlomiej.net/dotnet/embeded-assembies-into-an-executable/
The way we eventually handled this is by adding the localization XML files (generated by Visual Studio) as CRM resources, and created a bit of custom code which seeks the appropriate resource and then seeks the localization text inside.
It's, obviously, not as simple as just using the generated C# localization class, and requires some prep work. However, with that prep-work in place and with using nameof it's now almost as simple as the aforementioned resource classes.
I am creating web application in C# using ASP.NET MVC and I am using MSSQL server installed on my machine.
Also I wanted to publish application as open source project, and run it on production server.
Should I add web.config file to source code repository? If i should, how I should track "open source version" (pointing on MsSQL installed on localhost) and production version (pointing on my hosting of web.config (I am using Mercurial).
The recommended way to do this is as follows:
Create a copy of the public version of the file you'd like people to use as a starting point, and name it something other than the actual usable file. In your case, it could be web.config.template. Make sure the file would be usable if you just renamed it.
Instruct Mercurial to ignore the actual file, ie. web.config
If possible, make the build process figure out if the actual file is present, and if not, make a copy from the template file into the actual file
If step 3 is not possible, a batch file to make the actual file is the next best thing, or simple instructions on how to make it.
This ensures that:
There is a simple way of getting the actual configuration file
You can edit your local actual configuration file without worrying about committing it (it is ignored)
If step 3 was possible, this is largely transparent unless you need to make modifications to the file
Step 3 can be handled with a pre-build event for your project, something like:
if not exist web.config copy web.config.template web.config
You could commit a generic version to your repository, probably on the initial load only (so that the project will build for those who don't know how to create their own), and then add an ignore rule later so that you can add your connection strings and whatnot.