I have been working on a c# project in VS2017 Community. It's been fine for 6-8 weeks. I went away for the weekend and came back and I'm now getting an exception in my code that was not there previously.
System.Runtime.InteropServices.COMException: 'Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))'
At work I am logged into our company domain with Admin privileges. I was also working on this at home on my laptop to I tried it there and it's fine. Copied the project from laptop back to my desktop in the office and again get the exception.
Finally tried logging out of the computer and logging back in as a local user, and the code runs fine, no exception.
When logging back into the domain I tried running VS2017 'as Administrator' but same problem - exception get thrown. I removed all the most recent Windows Updates but no relief.
I really have to be logged in to the domain in order to do most of my other work, so I'm fairly at a standstill right now.
The purpose of the offending code is very basic - just creating a playlist (from a folder full of files) The code here's the code I'm executing that throws the exception when I'm logged in as a Domain account:
WMPLib.IWMPPlaylist playlist = wmp.playlistCollection.newPlaylist("myplaylist");
Related
I have read other questions on SO in regards to security and registry keys, nothing has helped me solve my particular use case scenario.
Here's my scenario:
What I'm Trying To Do
I want to, in code, delete a windows event log.
The Problem
When executing the function, I receive a System.ComponentModel.Win32Exception. The exception message is "Access is denied".
How I Am Doing It Currently
I am using an impersonator function that I wrote which wraps around the EventLog.Delete function, it drops me into a user context that has full access to the EventLog Registry Hive. Subsequently the logs I am interested in also have full access for this particular user.
My Question
Why do I receive a "Access Is Denied" if the user I am running under (through impersonation) has full access to the log in question? I've tested my Impersonation function and it works as expected for other code I've written. I don't get why I would get access denied for this.
In another scenario with my impersonation function it works just fine, for example if I tried to write to a file that the user context that is running the program does not have write access to, then I would not be able to write to the text file, however if I use my impersonation to drop into a user context that does have write access then it works just fine (I can write to the file). So I just don't understand why the same concept can't be applied to registry keys.
What am I missing here?
The Code
Exception Message
My Test
Where sw-test is a user I created for testing purposes, it has full access permissions to the registry we are trying to delete.
[TestMethod]
public void DeleteEventLog_ValidatedUser_DeleteLog()
{
using (new Impersonator(Environment.UserDomainName, "sw-test", "pswd"))
{
Logging logging = new Logging();
logging.DeleteEventLog("testLog");
}
}
Okay I eventually got around to figuring this out, there were two issues at play here that were causing the mentioned exception being thrown, they are as follows:
1. Visual Studio was NOT running in administrator mode.
Not running visual studio in administrator mode was one part of the problem, this seems to be associated with access tokens in the windows OS. According to a source I read, if I run a program without UAC on (which is my scenario, I have it off), then the program being run gets a copy of my access token. However if I have UAC enabled, the program gets a copy of my access token but it is a restricted access token. (see: What precisely does 'Run as administrator' do?) - To be honest this doesn't really make sense in my case, why do I have to run as admin if I have UAC off? Shouldn't visual studio have an unrestricted copy of my access token? I am in the administrator group with UAC off...
2. Not Specifying NewCredentials As a Logon32Type In Impersonation
I don't really understand it but as soon as I specified this for my impersonation everything started working perfectly, I read a blog about it, it talks about how it was introduced in the VISTA days and how it was mainly used to specify credentials to outbound network connections to servers, and was mainly used to remedy security-related issues server-side. Don't see how it correlates to interfacing with local event logs though. (see: https://blogs.msdn.microsoft.com/winsdk/2015/08/25/logonuser-logon32_logon_new_credentials-what-is-this-flag-used-for/)
Code
using (new Impersonator(Environment.UserDomainName, "sw-test", "pswd", Advapi32.Logon32Type.NewCredentials))
{
EventLog.CreateEventSource("testSource", "testLog");
EventLog.Delete("testLog");
}
Where the NewCredentials is an int 9
As of today all branches of our codebase (old and new), our staging environment and our live environment are all throwing the following exception when the Index method of any Controller is viewed in a browser:
System.Web.HttpException: The controller for path '/null' was not found or does not implement IController.
To clarify, this is even happening on code that has long since been checked in and has not been edited, when I open the project and browse to the homepage of the application. Other members of the team are also experiencing this on their own branches as of this morning too.
The exception is thrown but the respective Index page is rendered as you'd expect so the exception being thrown is silent to the user.
It looks to have started happening on our production site at just after midnight. No publish was undertaken and no Windows Updates were installed on the server. I did install yesterday's wave of Windows Updates on my own PC. I'm baffled! Any ideas?
I have an application that calls
Email hello = new Email(appropriate constructor);
hello.Email_Send();
I'm receiving the exception:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
from System.Runtime.InteropServices.COMException.
using O = Microsoft.Office.Interop.Outlook;
class Email
{
public void Email_Send()
{
O.Application outlook = new O.Application(); //Exception thrown here.
O.MailItem message = outlook.CreateItem(O.OlItemType.olMailItem);
message.To = Receiver;
message.CC = Sender;
message.Subject = Subject;
message.Body = "This is an automated message sent at " + DateTime.Now.ToString("HH:mm:ss") + " about " + Body_Topic + System.Environment.NewLine + Body_Content ;
message.Send();
}
}
This error has never happened previously, and there has been no change to the code that I know of. http://support.microsoft.com/kb/825118 doesn't seem to fit the my symptoms - My computer doesn't stop responding, etc.
Any help diagnosing the issue would be greatly appreciated!
This error was caused by visual studio being run as admin. Outlook doesn't allow separate users to access the same mailbox (I had the outlook application open on desktop). Even though I have local admin access w/ my domain user, running VS as admin must associate the process to a different user object? Not exactly sure how this works, but... Resolved.
I ran into the same issue, and as previously said: if Visual Studio is running as Administrator then Outlook prevents another instance with a different user. My VS solution is starting several projects, and I need it to run as Administrator, so what I did is run Outlook as administrator while debugging. This solved my problem.
Posting one of the comments as an answer.
When we close the running instance of Outlook it works like a charm.
In my situation I'm running under VMs with special security software. On my developer desktop it worked fine when Outlook was open.
But in my secured VM I had to close outlook in order to get this to work. This is likely to due our security software.
When outlook is left running: Unhandled Exception: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
When it is not running, it works fine.
The accepted answer is not entirely accurate. Actually, the COM will fail if the calling application does NOT have the same access level as the original process. Both need to be at the same access level.
So, if Outlook was started as Administrator and the program being debugged in Visual Studio is also administrator, it will work.
Vica-versa: if Outlook was NOT started as Administrator, then the program being debugged in Visual Studio will also need to be NON-administrator.
Also, you can get this message if not also included a COMReference to Microsoft.Office.Core.
I have a webservice on one of my websites which restarts the websites app pool.
The problem Im getting is the IIS7 app pool keeps stopping with the following warning and then error:
Warning:
A process serving application pool 'appPoolNameHere' exceeded time limits during shut down.
Error:
Application pool 'appPoolNameHere' is being automatically disabled due to a series of failures in the process(es) serving that application pool.
The code I am using to do this is:
try
{
var serverManager = new ServerManager();
var currentPoolName = SettingsManager.AppPoolName;
if (!string.IsNullOrEmpty(currentPoolName))
serverManager.ApplicationPools[currentPoolName].Recycle();
HttpRuntime.Close();
}
catch (Exception ex)
{
var exceptionManager = ExceptionManagerFactory.GetExceptionManager();
exceptionManager.LogException(ExceptionManager.Severities.Critical, ex,
"App Pool restart failed");
}
I am not getting any exceptions being thrown here, but the app pool is stopping, this doesnt happen all the time and is very hard to replicate, I have tried several different things even just hitting the hell out of that service and sometimes its fine other times it dies.
Is there anything I can do to fix this?
The reason I have to restart it is due to an external config file to the webconfig which deals with the url redirects which is updated from the admin system.
Thanks for any help with this.
Well I seem to have sorted (not fixed) the issue, with some tape and sticky-back-plastic.
The solution
Changed app pool setting: Rapid-Fail Protection to false
This stops IIS from killing the app pool after several failed requests to it.
I also added in retry system, so if the recycle request fails it waits for 10secs and tries again, it will do this 5 times before giving up and sending out an exception notice.
This has fixed the problem, and everything seems to be working well again, although something about this screams this is wrong!! at me.
Only if IIS would monitor other files in a website and restart the app pool when it saw a change.
I didn't work with Microsoft.Web.Administration namespace, but what about unloading application domain and sending request to your website so that to start application again?
Good example (2nd point) by Peter Bromberg how to do this.
Update.
Reading error stack
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()
I thought of most common reason: insufficient rights. All administrative actions require administrative rights. When code above is executed, which user account is impersonated? IUSR? Switch to any admin for that block and it should work without exception.
I have an Xbap application that is part of an intranet application that needs file system access.
Ive made the app full trust, signed it with a valid certificate and imported the cert into ie and the xbap works perfectly.
My issue is that I want to gracefully handle a Permission Denied exception if the user doen't have the certificate installed, ie does not have File system IO access
I thought I could achieve this by running the xbap in partial trust mode and using something like the following to test for permissions
CodeAccessPermission p = new FileIOPermission(FileIOPermissionAccess.Write, #"c:\newfile.txt");
try
{
p.Demand();
// Has access
}
catch (Exception ex)
{
// Does not have access
}
The issue is however that the above code will always fail if you have not added the FileIOPermissions permission to the "Permissions required by the application" list in the security tab of your project's properties window... even if run from your local file system instead of through a web server.
BUT
If i do add the FileIOPermissions permission, and the user does not have the certificate installed, none of my code is ever hit and the xbap throws a generic "Trust Not Granted" error screen... which i dont want, i want to show my users a proper error screen that explains what they can do to fix this error
any ideas?
You can manually edit the app.manifest file to request lower minimum permissions for your application, and then (in theory) you testing code will not always fail when you ask for the file permission, but as intended will fail only when user has not granted your code the required permissions.