System.ComponentModel.Win32Exception: Access is denied..... Error - c#

I want to open one document file on our website. For that I write following code.
try
{
Process proc = new Process();
proc.StartInfo = new ProcessStartInfo(Server.MapPath("~/Quatation/PREMIUMQUOTATION1.doc"));
proc.Start();
}
catch (WebException we)
{
}
It runs locally very fine but web on web server it gives me an error like
System.ComponentModel.Win32Exception: Access is denied?
Please suggest, what should I do?

I had this problem when my .NET Target Framework was set to 4.5.2. I fixed it by changing the target framework version to 4.5. To do this using Visual Studio 2015, open Solution Explorer, right click on your solution and click Properties. The "Target Framework" should be set to ".NET Framework 4.5". Additionally, if you previously built with a target framework other than 4.5, you may have a <compiler> section in your web.config, and this may throw an error when you build. Just remove this section to fix the issue. Removing it should not cause any problems.
I wrote a short article about this here that has a couple other things to try that didn't work for me but might work for you.
Also check out This Stack Overflow answer which also helped numerous people with this error!

may be your SQL server is off
check it in services and start it

It sounds like you haven't changed the service logon user. You can do it from service control manager by right clicking the service and go to the Logon tab.
Then add user as Service Logon User
Or you can do it from the command line:
sc config ServiceName obj= Domain\user password= pass
Note the space between obj= and Domain\user it is not a typo. It is required. The same for password=.

My problem solve with this
In IIS Manage->Pool Application->Advance Setting->Identity
change to Custom Account and set Administrator User

Goto windows explorer and right click on the folder "~/Quatation/". Select properties and pick the Security tab to give permissions. In the case where your application pool under which the web application runs is using a domain account, you will need to give that specific domain account permission.

I faced the same issue while running my website from local IIS, after spending some time reading the project properties, found that, certain changes to the project properties were not saved...
Once it was saved, the error went away...
I got this error while I was working in visual studio 2017, using dotNet framework 4.5, in MVC project...

If you are getting this exception maybe you don't have the administration rights to your system so check with your admin and ask for the rights. If you do have administrator rights please open your IDE(e.g Visual Studio as an Administrator).You might also get this exception if you are trying to access the processes of 32 bit configuration system but your system has 64 bit configuration.

I am using .Net 4.5.2 and IIS 8.5.9
In IIS Manage->Pool Application->Advance Setting->Identity change
ApplicationPoolIdentity to Custom Account and set Administrator User

Related

VS 2017 : The security debugging option is set but it requires the Visual Studio hosting process which is unavailable

My solution (which contains a dozen projects) works perfectly in Visual Studio 2013.
In Visual Studio 2017, I can open the solution and compile it.
But if I start the debug, I systematically get this error message:
The security debugging option is set but it requires the Visual Studio
hosting process which is unavailable in this debugging configuration.The
security debugging option will be disabled. This option may be re-enabled in
the Security property page. The debugging session will continue without
security debugging
And then, nothing happens. Nothing starts.
For information, this is a solution with multiple startup projects (including a WPF project).
Edit :
By disabling the option "Enable ClickOnce security settings" under Project -> Properties -> Security tab, it works.
This solved my issue:
Most likely, you have accidentally gotten the bit flipped to debug
with ClickOnce security settings. Can you get the project properties
for your app, go to the "Security" tab, and make sure to uncheck
"Enable ClickOnce Security settings" or check the "This is a full
trust application" radio button.
In case it helps anyone else - I have the same scenario - a multiple startup solution that includes a client that will be deployed with ClickOnce. To eliminate the problem that the client doesn't start after getting the Security Settings dialog, I moved it higher in the list in the startup projects dialog. If the client project is above the server project in the list, no error, everything debugs. If the client project is below the server project, then I get the error and the client never opens. This doesn't exactly SOLVE the problem but is a perfectly adequate workaround for me.
EDIT: You might need to close and reopen your Visual Studio for this workaround to be effective.
I spent hours trying to figure out the issue, this resolved it.
Go to Projct > Properties... > Build
Uncheck the checkbox Prefer 32-bit
MS have removed the VS hosting process in VS2017 - see
https://vslive.com/Blogs/News-and-Tips/2017/02/Debugging-Visual-Studio-2017-aims-to-speed-up-your-least-favorite-job.aspx
Because of this changing the EnableSecurityDebugging setting in the project user file to True simply results in the Error dialog appearing again at run-time.Clicking on OK in the dialog changes the user file setting back to False.
AFAIK there is no workaround although MS seem to be posting very frequent VS updates (latest is 15.3) In the meantime ClickOnce apps. will be unable to use the security debugging option.
This could likely be a glitch in some configuration file. The "Enable ClickOnce security settings" was already unmarked in the project settings but still this dialogue appeared every time the application was started. I did the following to get rid of this dialogue:
Open the project->security setting page
Mark "Enable ClickOnce security settings"
Unmark "Enable ClickOnce security settings"
Save the properties and start the application again
Properties
Here's a workaround that enabled me to debug my ClickOnce app.​ in VS2017 without getting the error message "Unable to determine identity of caller" when accessing Isolated Storage. The workaround should also work in any situation that requires the ClickOnce security settings.
To recreate the settings that were previously generated when the Enable ClickOnce security settings on the Security tab of the project's properties was checked, do the following:
1.Uncheck Enable ClickOnce security settings on the Security tab of your project's properties
2.Add the following to your App.Config file if not already present
<runtime>
<NetFx40_LegacySecurityPolicyenabled="true"/>
</runtime>
3.Add a reference to ​Microsoft.Build.Tasks.v4.0 to your project
The code to recreate the ClickOnce settings can go anywhere, but the following sample Main method illustrates the general idea
using System;
using System.Reflection;
using System.Runtime.Hosting;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using System.Windows.Forms;
using Microsoft.Build.Tasks.Deployment.ManifestUtilities;
namespace SecurityDebuggingTest
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0 && args[0] == "startui")
{
Application.Run(new Form1());
}
else
{
PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
string AppName = Assembly.GetEntryAssembly().GetName().Name;
string AppExe = $"{AppName}.exe";
string DebugSecurityZoneURL = $"{AppExe}.manifest";
string AppManifestPath = $"{AppName}.application";
string appType = "win32";
AssemblyIdentity ca = AssemblyIdentity.FromManifest(AppManifestPath);
string appIdentitySubString = $"Version={ca.Version}, Culture={ca.Culture}, PublicKeyToken={ca.PublicKeyToken}, ProcessorArchitecture={ca.ProcessorArchitecture}";
string assemblyIdentity = $"http://tempuri.org/{AppManifestPath}#{AppManifestPath}, {appIdentitySubString}/{AppExe}, {appIdentitySubString},Type={appType}";
System.ApplicationIdentity applicationIdentity = new System.ApplicationIdentity(assemblyIdentity);
ApplicationTrust appTrust = new ApplicationTrust();
appTrust.DefaultGrantSet = new PolicyStatement(permissions, PolicyStatementAttribute.Nothing);
appTrust.IsApplicationTrustedToRun = true;
appTrust.ApplicationIdentity = applicationIdentity;
AppDomainSetup adSetup = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
ActivationArguments = new ActivationArguments(
ActivationContext.CreatePartialActivationContext(
applicationIdentity,
new string[] { AppManifestPath, DebugSecurityZoneURL })
),
ApplicationTrust = appTrust
};
Evidence e = new Evidence();
e.AddHostEvidence(appTrust);
AppDomain a = AppDomain.CreateDomain("Internet Security Zone AppDomain", e, adSetup, permissions);
a.ExecuteAssembly(AppExe, e, new string[] { "startui" });
}
}
}
}
You may see the warning message about the VS Hosting process being unavailable when you first run the above code but thereafter the EnableSecurityDebugging setting in your project's user file will have been set to False and the code should run as normal.
Thanks to Microsoft's ClickOnce team for their help on this workaround.
I have yet another cause for why this message may come up. In my case, while testing cloning my solution from Git, I noticed that Visual Studio decided to set the Active solution platform to "Any CPU", whereas my startup project is explicitly targetting "x86". This caused the startup project to not build when I ran the build solution command.
Checking the Build box in the Configuration Manager for that project got rid of the error message.
In case anyone asks, I don't remember exactly why that one project is explicitly targetting x86.
I just had the same issue. Prefer 32-Bit was disabled.
I looked in the Output Path and it was bin\Release.
I created a bin\debug path and set the Output Path to this.
Resolved.
For me the solution was to switch to "The application is available offline as well" in Publish tab of project properties
Before I had "The application is available online only"
My issue seemed to be associated with the folder that the solution was in. My DEV branch solution worked without issue but the CERT branch (different local folder) gave the Security Debugging message when the ClickOnce Security settings were checked.
My solution: launch VS2019 as Admin. Problem is gone when debugging. And now I can launch without Admin and debugging is still good.
A quick solution with no explanation on why: Running my application in "Debug" configuration stopped the error and allowed my application to run.

Unable to run Console Application from Visual Studio: System.AccessViolationException

Description
When launching any Console Application, the code stops running immediately on an AccessViolationException (Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt). More info included in the next section.
Technical Symptoms
The Call Stack only contains external code:
Exception:Thrown: "The message filter indicated that the application is busy. >(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" (System.Runtime.InteropServices.COMException)
A System.Runtime.InteropServices.COMException was thrown: "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))"
Time: 12/10/2015 10:59:55 AM
Thread:vshost.NotifyLoad[15344]
I created a new Console Application, containing only Console.WriteLine("Hello world!");
Running the new Hello world app results in the same exception and an identical
call stack.
Background
I suspect this has nothing to do with the issue, as I will explain, but I feel it is important to answer the obvious question, "what were you doing when the issue happend?" The last change I made was adding an extension to my Selenium Driver to hotkey logout from an application:
public static void logout(this IWebDriver Driver)
{
Driver.FindElement(By.TagName("body")).Click();
new Actions(Driver)
.SendKeys(Keys.Control + Keys.Shift + "x")
.Perform();
}
I also made a change in my App.Config file for one of my projects, but reverting this had no impact either.
Removing this code (the Driver extension and/or the App.Config change) does not resolve this issue. Retrieving a previous check-in does not resolve the issue. I am the only person currently working on this solution.
Discoveries
As mentioned, this is happening for an empty Console Application. Windows Form Applications launch fine. Unit Test Projects launch fine as well.
Research
I've spent hours looking into this. It seems like every similar issue I have looked into is pertinent to debugging only or a .NET version. For me, the issue occurs with a Release as well. Additionally, I have been using .NET 4.5 without any issues or changes on that front. I can't find any articles that seem worth posting, but I might be overlooking something.
Visual Studio Info
Microsoft Visual Studio Ultimate 2013
Version 12.0.30501.00 Update 2
.NET Version 4.6.00081 (just noticed it says 4.5 in my project properties, though)
Running as Administrator
Feedback
When Running from devenv.exe /SafeMode, Visual Studio loaded with:
An exception was encountered while constructing the content of this frame. This information is also logged in "C:\Users\UserName\AppData\Roaming\Microsoft\VisualStudio\12.0\ActivityLog.xml".
Exception details:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid& packageGuid, Int32 reason, Guid& context)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()
Additionally, when trying to run, I get an error message of "Error while trying to run project: Invalid Pointer" (again, VS in devenv.exe /SafeMode - see how to run visual studio without plugin and all third party feature if unfamiliar)
Please let me know if I can provide any additional information.
It may be because when you name the project you can't put spaces, I put them and it gave me a AccessViolationException aswell, try using capitals to separate your words, but only use letters and no spaces to be sure.
I also faced this issue with Visual Studio 2010. More interestingly I had several projects in my solution (Console application, WPF application, Windows Forms application) but it was failing only when, I was setting the project which was of type "Console Application" as start up project. Following change finally helped me nail down the issue: Go to project properties of the console application project -> Go to "Debug" tab -> Go to "Enable Debuggers" section in right pane -> Check the "Enable unmanaged code debugging" check box as shown in the snapshot below. Root cause of why it happened is still not known to me. Only thing which I observed as fishy was that there were lot of windows updates which had got installed on my machine the previous night which mostly constituted of office updates and OS updates (More than a dozen KB articles).

silent uninstall msi package command WITHOUT administrative rights

I am trying to uninstall a program from my visual studio project but that seems to requiere me to run vs as an admin....so i tried doing this from the cmd to debug it .
I have managed to uninstall a msi setup project installation with this command from cmd :
msiexec /x {3A40307D-6DF2-4412-842F-B1D848043367} /quiet , but that only works when i start cmd as an admin, without admin rights it wont uninstall. What am i doing wrong and is there another approach to get the result I want?
I want to be able to silent uninstall an application without having to ask the user to login as an admin.
Edit:
This is the result from the log :
Error 1001. Error 1001. Unable to delete file C:\ProgramData\XXX.InstallState.
DEBUG: Error 2769: Custom Action _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall did not close 1 MSIHANDLEs.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2769. The arguments are: _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall, 1,
CustomAction _F6174138_B428_4AB6_9FEF_C4DD7A69BDC0.uninstall returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 17:54:40: InstallExecute. Return value 3.
Action ended 17:54:40: INSTALL. Return value 3.
MSI (s) (F0:3C) [17:54:40:355]: Product: XXX -- Removal failed.
That error from the log file indicates that a custom action is crashing. You'll want to investigate the root cause of that issue. My guess is that the custom action requires elevation (admin privileges) to work correctly but is not marked deferred (i.e. runs during the part when the MSI is elevated).
If you launch the uninstall of the MSI from Add/Remove Programs (Programs and Features) then you should not be prompted for elevated credentials. Thus the root issue probably is this custom action.
It appears you have several options here. All of them require creating an msi that doesn't require Admin privileges from the start. If the msi requires them from the start (eg, you have no control over the creation of the msi), there is no way around it. It all depends on what files are being edited as to whether or not admin rights are really required. Check out this answer: How can I create a windows installer MSI that does not require admin access

c# OPC Automation gives 80040154

I am a .Net developer. New to OPC. When I tried some samples of OPC Client all of them give this error. It seems the DLL is not registered it seems. But I don't know how and where to register this.
error: retrieving the COM class factory for component with CLSID failed due to the following error: 80040154
Even I tried this
regsvr32 Interop.OPCAutomation.dll",
but it also throws error like
The module "Interop.OPCAutomation.dll" was loaded but the entry-point DllRegisterServeer was not found.
Make sure that "Interop.OPCAutomation.dll" is a valid DLL or OCX file and then try again.
I have gone through so many existing forums. So many of them said to change the Platform Target to x86 and still I am having the same issue. FYI, I can see only see 'Active (Any CPU)' in the Platform option from the top of the Build tab of Project Properties.
Here are my environment details:
.Net 2005
OPCAutomation Weapper
Windows 7 64-bit OS
Dell Inspiron 1525 (I hope this is not a 64bit machine, but my engineer installed 64bit OS somehow).
Please help me.
Thanks in advance!
Just in case somebody is dealing with this problem (as I've recently been...) I get through it! After some time, I found out that it's something about the .NET framework running on 64-bit machines. As long as the.NET application works only with 32-bit CLR, we must set .NET framework to load CLR in WOW mode. To do so, type:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe SetWow
After this you should be able to run the applications.
You can go back and revert .NET Framework as it was before by typing:
C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\Ldr64.exe Set64
If the OPC Client Toolkit SDK (C++) is used, a problem with the remote registry service may cause this error as well.
On Windows 7, by default the Remote Registry service is set to manual and not started. Ensure that the Remote Registry service is started on all of the machines you want to deploy to. This can be done manually or using Group Policy.
The function GetCLSIDFromRemoteRegistry() uses the RemoteRegistryService in order to get the CLSID of an OPC Server. If this service is not started on the client machine, the OPC program may return the error 80040154.
The error you're getting is more than likely due to the OPC server not being properly registered. Make sure it is registered (usually by running it at the command line with a "/regserver" or "/service" parameter). There may also be security issues in which case you'd have to run 'dcomcnfg' (DCOM Config) to make sure the client has access to the server.
This question is a bit dated so I hope you figured it out by now, but I had the same exact issue and wanted to share my solution. In my case, I am using a Kepware server. If you compile and try to run a client application for this server using Interop.OPCAutomation on a machine that does not have the server installed, you will get a dll not registered error and "entry point not found" if you try to register the dll manually.
Solution: Make sure you've got the server installed and running.
Although this is an old post, I would like to share my solution.
My problem was that when I tried to install an application with the OPCAutomation.dll, it gave me 80040154 error because the class was not registered.
This is my solution, always with Administrator privileges:
Copy OPCDAAuto.dll into the "C:\Windows\System32" folder
On the cmd prompt type "C:\Windows\System32\regsvr32 opcdaauto.dll"
You should watch a message like this one:
image
Hope this helps!
The OPC dll only works in 32 Bits, my solution was to change the "Enable 32-Bit Applications" to True in the advanced settings of the relative app pool in IIS.

Easyhook fires "Unable to install assembly in the GAC" error on vs2010

I'm still trying to run my easyhook exercize. right now, i get this error:
System.ApplicationException: Unable to install assembly in the GAC. This usually indicates either an invalid assembly path or you are not admin.
at EasyHook.NativeAPI.GacInstallAssembly(IntPtr InContext, String InAssemblyPath, String InDescription, String InUniqueID)
at EasyHook.Config.Register(String InDescription, String[] InUserAssemblies)
at HookTest.Program.Main()
and the problem seems to originate here:
Config.Register(
"Easy hook test",
"Hook Test.vshost.exe",
"TestInject.dll");
The solution I'm trying to build is composed by two projects, a library and an application. Once I build the solution, i copy testinject.dll to the hooktest debug folder, and then I run it in debug mode.
Maybe I should use an absolute path to indicate where testinject.dll is? or add the library somewhere?
UPDATE 1
"Easy hook test",
#"Hook Test.vshost.exe",
#"I:\Documents and Settings\foo\Desktop\Hook Test\TestInject\bin\Debug\TestInject.dll");
Even with this change, I get the same error
Try changing the target framework from 4.0 to 3.5, that should do the trick.
This usually indicates either an invalid assembly path or you are not admin.
That's as good an error message as you can expect. The path could be wrong because you don't specify the full path of the assembly (i.e. c:\mumble\foo.dll). You commonly don't have admin rights because of UAC. Use a manifest to get the privilege elevation or run Visual Studio in admin mode (change the desktop shortcut).
Even though you yourself are an Admin, it does not mean that apps that you run will be elevated to admin. In fact, VS 2010 will NOT be, nor will most others. You actually have to right-click "Run as Admin...". I actually set my VS start menu shortcut's properties to "Run as Administrator" so that I never forget, as I was burned on this too.

Categories