I have a WCF service which will will be called from mobile devices and that service will zip some folders in the machine and will send it back to the caller.I use dotnet zip for zipping the folders in my WCF service.
I am getting the following error trace from the open source dotnet utility , that i have used in my project.
"Request for the permission of Type 'System.security.Permissions.FileIOpermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublickeyToken=dfsdfsdfsdfds' Failed"
I am using the dotnet zip utility to zip my folders and files avaiable in my machine.
I tired one option, by cleaning the solution and building it with Administratice privilege it started working but after sometime the same problem comes again.
Please help me in resolving this.
I don't know which WCF hosting option is your choice, but if this is Internet Information Services, it seems that these are some reasons of having this exception:
1) IIS worker process doesn't have permissions over the folders to zip or the temporary folder where you place the Zip file that the service sends.
2) Web configuration has a very low trust in service code. Check that this is in medium or full-trust mode.
3) The way you're opening the file is wrong. Check how you open the file stream and see if this is doing with the necessary file mode (OpenRead or like this).
I don't think this is a compilation problem. It's a run-time issue.
Related
i developed a small windows service where sql dependency classes to monitor table changes. if table change occur then service call a web service. this service create a folder and file to save the log and also service send mail to user.
i try to copy service exe file in a folder of program files folder and issue this command installutil C:\BBA-Reman\PartIndexer\MyService.exe
getting error related message and i understood that permission is getting a issue. so i open the command prompt as run as admin and then i was my service is running fine and also could create folder & file for saving log data.
so what i did now. i add a Manifest.xml file in my project and make a association that file with my project. Manifest.xml file content here.
this area i change in manifest file for running my service with admin privilege
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
i again compile my service and just open command prompt without run as admin and issue the same command installutil C:\BBA-Reman\PartIndexer\PartIndexerService.exe getting the same permission issue related error message as before.
so please guide me how could i run my service with admin privilege by manifest file. what i am doing wrong for which i am getting error even after adding manifest file. looking for suggestion. thanks
I propose to use Topshelf in your C# application, it eases the process of windows services installation.
Here you can find more details about it:
http://docs.topshelf-project.com/en/latest/overview/commandline.html
I have a C# executable reading and updating it's configuration file (app.exe.config) at runtime, specifically, the "appSettings" section. After I make two changes to two key values and save them using the Configuration.Save() method, an "access to the path" error is thrown, but only on some users' machines (so far 2 reports out of 10,000). We have never seen this issue in-house, only in production.
The Configuration.Save() method seems to be the issue based on our program's log file. When a problem with this call happens a "ConfigurationErrorsException" occurs because the configuration file could not be written to -or- the configuration file has changed. The configuration file is in the same directory as the application. This is a Dot Net 4 application running on a Windows 7 PC.
The code is:
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings["Last Updated Package"].Value = packageVersion;
configuration.AppSettings.Settings["Copy Updated Files"].Value = bool.TrueString;
configuration.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
The error is:
An error occurred loading a configuration file: Acces to the path 'C:\Program Files (x86)\My Program\bin\guaixcax.tmp' is denied. (C:\Program Files (x86)\My Program\bin\MyProgram.exe.Config)
Is this a permissions issue, or can I add something to either the code or config file to fix this issue?
I have had similar issues with .NET program installations. It has always been a permissions issue. To test if this is your problem, you should try running your application as an unprivileged user - developers tend to have administrator rights...whenever they can manage it.
If it fails, edit the security of the config file (as an administrator) to allow the "Users" group write access to your "bin" folder, and try it again. If it works, you've identified the problem. Then you can figure out what the best solution is. Some options would be:
Set access rights to necessary files/folders from your installer to work for the users that will run the application
Run the application as a user with admin rights (NOT a good idea from a security best-practices point of view)
Instead of modifying the main app settings file, create a separate settings section referencing a file that has the data that can be changed:
<configuration>
<configSections>
...
<section name="MyChangableSettings" type="My.Namespace, ChangableSettingsClass"/>
</configSection>
...
<MyChangableSettings configSource="Path\To\Writable\StorageDir\mySettings.config"/>
</configuration>
I have a windows service program running in C#. I have configured to run it as a local service with my config files stored in \bin\release\config\configvalues.txt. But, it does not recognize this file path and throws the "System.UnauthorizedAccessException".
I believe its looking for the files in the System32 folder and since it does not have the privilege, throws out the exception. For the workaround, my service is running with "local system" to recognize the System32\config folder. To run as a local service, which file path should the config folder be available?
Check the location of your project folder. Most likely, you'll find that it is inside your User profile folders, which the local service account does not have access to.
Deploy your project to a folder outside of any User profiles and you'll have better luck.
I have setup a Console, Library, and Service project. The Library project loads up files in a folder and stores the text in variables.
The console project will then manipulate those variables. I am able to run the Console project successfully and it loads the files without a problem. The files are set to Copy Always in the DLL and are specified as Content for the Build Action.
When I try to run the exact same code in the service.
File.ReadAllText(#"MyFolder\SomeFile.txt");
It throws the following exception.
The type initializer for 'MyLibrary.Data.ReadFiles' threw an exception.
I am using the Setup Project type to create the installer. After the service installs the folder MyFolder does exist in the Application Folder of the service, as well as the files. What else could be causing my problem for the service not being able to read those files?
EDIT 1
public class ReadFiles {
public static string DataFile = File.ReadAllText(#"MyFolder\SomeFile.txt");
}
The service account that you're running the Windows service under, doesn't have rights to read from the location you're trying to access. The error you're seeing has to do with the fact that the code you showed likely exists in the construction of the type ReadFiles.
Was facing similar issue in one of the windows service for running node js application, for sending emails.
It was running fine when we run from the same directory, but running same application as windows service was having issues and couldn't send emails. Comment from #meanbunny did help, so adding it as an answer.
Windows service can't access the directory/files if they are mentioned in the code as relative path, better use the absolute path or be more flexible as #Mike mentioned in his comment to use app.config for each service.
I'm downloading from clickonce server new versions of files by my autoupdater. However, any time downloading cycle comes over MyApplication.exe.config file on the server webClient.DownloadFile(remoteFile, localFile) throws a System.Net.WebException with code 500 (internal server error or something like that). At the same time application event log renders few entries from asp.net, like
failed to initialize AppDomain /LM/W3SVC/1/ROOT
Exception: System.Configuration.ConfigurationErrorsException
asp.net process id doesn't have permission to access GAC
aspnet_wp.exe stoped.
But the cycle continues successfully for all other files.
Does it somehow figures that it is config file for a web server, since asp.net is .NET framework itself and "knows" about .config file?
As was already mentioned in the other answer, IIS will not serve .config files. Where my answer is different is the proposed work around: ClickOnce has an option to use .deploy files, where all your file names have a .deploy extension appended to them. This neatly gets around the IIS config transfer problem.
IIS, by default, does not serve up .config files. Do you have access to the IIS configuration on the ClickOnce server, so that you can see if .config is disallowed in the request filtering module?
In IIS 7, it's in Request Filtering in the IIS section. I'll see if I can find where that's configured in IIS 6.