E_ACCESSDENIED (0x8007005) when calling DsDevice.GetDevicesOfCat() function from DirectShowLib - c#

I have the following piece of code which is called from a IIS web service:
private IBaseFilter CreateFilter(Guid category, string friendlyname)
{
object source = null;
Guid iid = typeof(IBaseFilter).GUID;
foreach (DsDevice device in DsDevice.GetDevicesOfCat(category))
if (device.Name != null && device.Name.CompareTo(friendlyname) == 0)
{
device.Mon.BindToObject(null, null, ref iid, out source);
break;
}
return (IBaseFilter)source;
}
When DsDevice.GetDevicesOfCat()is called, the service throws the following exception:
Creating an instance of the COM component with CLSID
{62BE5D10-60EB-11D0-BD3B-00A0C911CE86} from the IClassFactory failed
due to the following error: 80070005 (Exception from
HRESULT: 0x80070005 (E_ACCESSDENIED)).
at DirectShowLib.DsDevice.GetDevicesOfCat(Guid FilterCategory) at
MyVideoRenderer.CreateFilter(Guid category, String
friendlyname) at MyVideoRenderer.Constructor(String
filepath, Int32 width, Int32 height, ISampleGrabberCB BufferCB,
ISampleGrabberCB BufferCBSource, Rectangle sourceRect)
This has happened both in a server running Windows Server 2008 R2 and a PC running Windows 7. I do have a Windows Form which calls the same code and it works in both machines.
I don't know which category/filter caused this error, but it does require a couple of .ax/dll to be regsvr32-ed before usage. These dlls are inside the webservice directory, so there should be no problem with permissions.
Any tips on how to fix this? Thanks.

Related

Function ...Workbooks.Open() is failed while opening .xla and .xla addins of excel through c# - HRESULT: 0x80010105 (RPC_E_SERVERFAULT)

I wrote a code in c# in Visual studio and I open excels, run macro and close the excel
I do it in cycles (in a loop and delay between every cycle)
sometimes the function failes and sometimes it works
The error message I got:
"The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))"
Please can someone help me ???
public void Open()
{
try
{
ExcelApp.Workbooks.Open(#"C:\Program Files (x86)\REFPROP\REFPROP.XLA");
ExcelApp.Workbooks.Open(#"C:\Program Files (x86)\REFPROP\REFPROP_Ribbon.xlam");
foreach (Excel.AddIn item in ExcelApp.AddIns)
{
if (item.Name.Equals("REFPROP.XLA") || item.Name.Equals("REFPROP_Ribbon.xlam"))
{
item.Installed = false;
item.Installed = true;
}
}
Thread.Sleep(3000);
//so then opening excel workbooks:
ExcelBook = ExcelApp.Workbooks.Open(ExcelPath);
Opened = true;
Thread.Sleep(3000);
ExcelApp.Workbooks.Open(#"C:\Program Files (x86)\REFPROP\REFPROP.XLA");
ExcelApp.Workbooks.Open(#"C:\Program Files (x86)\REFPROP\REFPROP_Ribbon.xlam");
foreach (Excel.AddIn item in ExcelApp.AddIns)
{
if (item.Name.Equals("REFPROP.XLA") || item.Name.Equals("REFPROP_Ribbon.xlam"))
{
item.Installed = false;
item.Installed = true;
}
}
Thread.Sleep(3000);
}
catch (Exception e)
{
throw;
}
}
There can be multiple reasons why you are getting that exception at runtime.
First, I'd suggest releasing underlying COM objects in the code and do not rely on the GC. Use the Marshal.ReleaseComObject method for that and then set the object to null.
Second, try to set the calculation mode to manual.
Third, make sure that the file doesn't require admin privileges.
You may find a similar thread helpful, see Excel interop The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).

"The server machine is shutting down. (Exception from HRESULT: 0x800704E7)" while accessing Windows.ApplicationModel.Store.CurrentApp

I have this fragment of code:
Uri uri;
try {
uri = Windows.ApplicationModel.Store.CurrentApp.LinkUri;
}
catch(Exception ex) {
// exception is thrown
}
I get the exception:
ex = {System.Exception: The server machine is shutting down.
(Exception from HRESULT: 0x800704E7) at
Windows.ApplicationModel.Store.CurrentApp.get_LinkUri() at
MyApp.Controls.Screens.MainScreenControl..ctor()}
What does it mean and how can I avoid this exception?
The similar, unresolved question is here: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6ebd1b23-b37b-4cc5-a840-d966527f7199/the-server-machine-is-shutting-down-exception-from-hresult-0x800704e7?forum=wpsubmit .
It looks like it was a temporary Windows Store server problem.

Crystal Reports PrintToPrinter throws exception after a time working fine

We have a WPF application that, among other things, prints reports approximately every two minutes using async sintax. The report is made using SAP Crystal Reports, version for Microsoft Visual Studio 13.0.15.1840. The computer in which application has been developed has also SAP Crystal Reports runtime engine 64-bit 13.0.15.1840. Below is the code for async code:
private async void StartAsyncOperation()
{
while (true)
{
try
{
if (_isActive)
{
await Task.Run(() =>
{
PrintTravelSheet();
});
await Task.Delay(_delayPrinterTime);
}
else break;
}
catch (Exception e)
{
SendWarningAlerts(string.Format("Error!!! You should be worried! \n {0}", e));
}
}
}
The application is deployed to a computer with Windows Server 2012 with SAP Crystal Reports runtime 64-bit 13.0.8.1216. Below is the code used by PrintTravelSheet for printing:
try
{//_hojaViajera is my Crystal Report
_hojaViajera = new HojaViajera();
InitializeTravelSheet(printerConfig, tracking, configBits);
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = printerConfig.PrinterName;
_hojaViajera.PrintToPrinter(printerSettings, new System.Drawing.Printing.PageSettings(), false);
}
catch (Exception ex)
{
//here I send emails with error log
}
finally
{
_hojaViajera.Close();
_hojaViajera.Dispose();
}
Usually the application works fine for two weeks or a little more, but after that time the thread that handles printing operations crashes and I receive the following exception:
** **Message Error: CrystalDecisions.CrystalReports.Engine.InternalException: There are not enough free System Resources to perform this operation.
Error formatting Field Object.
Error in File temp_1d4e04c2-7dc4-4896-a347-edc086582c07 {BFFFC1AF-E765-4FF0-BBEC-02929B533486}.rpt:
Low system resources.. ---> System.Runtime.InteropServices.COMException: There are not enough free System Resources to perform this operation.
Error formatting Field Object.
Error in File temp_1d4e04c2-7dc4-4896-a347-edc086582c07 {BFFFC1AF-E765-4FF0-BBEC-02929B533486}.rpt:
Low system resources..
at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.GetPage(PageRequestContext pPageRequestContext)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetPage(PageRequestContext pageReqContext)
--- End of inner exception stack trace ---
at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e)
at CrystalDecisions.ReportSource.EromReportSourceBase.HandleException(Exception exception)
at CrystalDecisions.ReportSource.EromReportSourceBase.GetPage(PageRequestContext pageReqContext)
at CrystalDecisions.CrystalReports.Engine.FormatEngine.QueryPageSettingsEventHandler(Object sender, QueryPageSettingsEventArgs e)
at System.Drawing.Printing.PrintDocument.OnQueryPageSettings(QueryPageSettingsEventArgs e)
at System.Drawing.Printing.PrintDocument._OnQueryPageSettings(QueryPageSettingsEventArgs e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, PrintLayoutSettings layoutSettings, Boolean reformatReportPageSettings)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, Boolean reformatReportPageSettings)**
**
Then I just close the application and start over again and all comes back to normal. So far I have not been able to reproduce the error on my machine or even on the server. Any help or workaround is welcome.

Unable to Connect to Virtual Serial Port

I'm writing a .NET application running on Windows CE 6 that creates a Bluetooth Serial Port. The call to RegisterDevice() returns successfully, and SerialPort.GetPortNames() indicates the the COM port exists. However, when I attempt to open the COM port using .NET's SerialPort class, it throws an IOException, stating that the port does not exist. If I attempt to open it using CreateFile, the call fails, and GetLastError returns error 6 (INVALID_HANDLE). However, if I create a registry key under HKLM\Software\Microsoft\Bluetooth\Serial and restart the device to allow the Microsoft Bluetooth Stack to initialize the port, I can connect to the serial port without issue. I'd like to avoid making the user restart the device, if possible.
My code to create the virtual serial port:
static public IntPtr RegisterVirtualComPort(int index, long address, Guid service)
{
PORTEMUPortParams portParams = new PORTEMUPortParams();
portParams.uiportflags = RFCOMM_PORT_FLAGS.REMOTE_DCB;
portParams.flocal = false;
portParams.device = address;
portParams.uuidService = service;
IntPtr handle = RegisterDevice("COM", index, "btd.dll", ref portParams);
return handle;
}
I attempt to test the COM port via P/Invoke here:
static public bool TestComPort(int index)
{
string portName = string.Format("COM{0}:", index.ToString());
IntPtr handle = CreateFile(portName, DESIRED_ACCESS.GENERIC_READ | DESIRED_ACCESS.GENERIC_WRITE, FILE_SHARE.FILE_SHARE_NONE, IntPtr.Zero, CREATION_DISPOSITION.OPEN_EXISTING, 0, IntPtr.Zero);
bool success = handle.ToInt32() != -1;
CloseHandle(handle);
if (!success)
{
int errorCode = Marshal.GetLastWin32Error();
App.Logger.DebugFormat("TestComPort failed for \'{0}\', return error code {1}.", portName, errorCode);
}
return success;
}
Any help would appreciated.

Unable to use IIS ADSI Provider after IIS installation if ADsOpenObject was called before install

My .Net application actively uses Active Directory and installs IIS if its absent.
If IIS wasn't installed on application startup and any of Active Directory-related methods were called then IIS ADSI Provider stills unavailable after IIS installation (after application restart it becomes available).
Unfortunately i cannot change the operations sequence, so it must be "use AD -> install IIS -> use IIS ADSI provider -> use AD"
My steps-to-reproduce code (not real) is:
using (Domain domain = Domain.GetCurrentDomain())
{
}
// IIS install here
using (DirectoryEntry entry = new DirectoryEntry("IIS://localhost/W3SVC/1"))
{
var options = entry.Options; // exception here
}
Changed sequence works fine:
// IIS install here
using (Domain domain = Domain.GetCurrentDomain())
{
}
using (DirectoryEntry entry = new DirectoryEntry("IIS://localhost/W3SVC/1"))
{
var options = entry.Options;
}
Using Reflector i have found that it is enough to call ADsOpenObject once to make IIS ADSI provider unavailable after IIS installation.
class Program
{
static void Main(string[] args)
{
object ldapPPObject = GetAdsObject("LDAP://TestDomain.local/RootDSE");
Marshal.ReleaseComObject(ldapPPObject);
// IIS install here
object iisPPObject = GetAdsObject("IIS://localhost/W3SVC/1"); // exception here
Marshal.ReleaseComObject(iisPPObject);
}
private static object GetAdsObject(string path)
{
Guid iid = new Guid("00000000-0000-0000-c000-000000000046");
object ppObject;
if (IntADsOpenObject(path, null, null, 193, ref iid, out ppObject) != 0)
{
throw new Exception("ADsOpenObject failed");
}
return ppObject;
}
[DllImport("activeds.dll", EntryPoint = "ADsOpenObject", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int IntADsOpenObject(string path, string userName, string password, int flags, [In, Out] ref Guid iid, [MarshalAs(UnmanagedType.Interface)] out object ppObject);
}
I have tried to create separate app domain and place there code that uses IIS but this try was failed too.
How can i force AD reinitialization to get IIS ADSI provider available after IIS installation?
.Net had nothing to do with the problem.
The following c++ code fails too:
int _tmain(int argc, _TCHAR* argv[])
{
IADs *pObject;
HRESULT hr;
CoInitialize(NULL);
hr = ADsOpenObject(L"LDAP://TestDomain.local/RootDSE", NULL, NULL, 193, IID_IADs, (void**) &pObject);
if(SUCCEEDED(hr))
{
pObject->Release();
}
// install iis here
hr = ADsOpenObject(L"IIS://localhost/W3SVC/1", NULL, NULL, 193, IID_IADs, (void**) &pObject);
if(SUCCEEDED(hr)) // not succeeded
{
pObject->Release();
}
CoUninitialize();
return 0;
}
But the trouble still need to be solved somehow...
There is no way to get the ADSI provider working again after the call to ADsOpenObject. Sorry.

Categories