【发布时间】:2020-11-03 14:12:43
【问题描述】:
我有一个使用框架 4.5.2 升级到框架 4.8 的 Windows 服务。但是现在该服务不再工作了,因为错误:System.ApplicationException: CoIntializeSecurity failed w/err 0x80010119
这是在 4.5.2 下工作但在 4.8 下不再工作的代码
public Service()
{
// Initialize COM security
UInt32 hResult = COMNative.CoInitializeSecurity(
IntPtr.Zero, // Add your security descriptor here
-1,
IntPtr.Zero,
IntPtr.Zero,
COMNative.RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
COMNative.RPC_C_IMP_LEVEL_IDENTIFY,
IntPtr.Zero,
COMNative.EOAC_DISABLE_AAA | COMNative.EOAC_SECURE_REFS |
COMNative.EOAC_NO_CUSTOM_MARSHAL,
IntPtr.Zero);
if (hResult != 0)
throw new ApplicationException(
"CoIntializeSecurity failed w/err 0x" + hResult.ToString("X"));
}
/// <summary>
/// Called when [start].
/// </summary>
/// <param name="args">The arguments.</param>
public void OnStart(string serviceName)
{
ILogger logger = LoggerService.GetLogger();
logger.Info("*** START OF SERVICE ***");
logger.Info(serviceName + " (Version " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ") starting ....");
Guid clsidSQLEventObj = new Guid(ComponentClassId);
// Register the SQLEvent class object on start
UInt32 hResult = COMNative.CoRegisterClassObject(
ref clsidSQLEventObj,
new SQLEventClassFactory(),
COMNative.CLSCTX_LOCAL_SERVER,
COMNative.REGCLS_MULTIPLEUSE,
out _cookieSQLEventObj);
if (hResult != 0)
throw new ApplicationException(
"CoRegisterClassObject failed w/err 0x" + hResult.ToString("X"));
}
我们已经尝试了多种安全设置,但都没有成功。
有没有人知道在这种情况下 4.5.2 和 4.8 之间有什么区别,为什么它不再工作了?
【问题讨论】:
-
汉斯,我们的应用程序不是 WPF 应用程序,它是控制台/Windows 服务,我们没有定义 STA 线程。