In my current project we have a COMInterface that we intialize in the beginning of the Code. It worked fine in VS2010 and VS2013 and we haven't made any changes. I can compile and run the code from VS2013 but the same code doesn't work in VS2017. I have tried 2 different machines.
The error given is
System.Runtime.InteropServices.COMException
HResult=0x80010119
Message=Security must be initialized before any interfaces are marshalled or unmarshalled. It cannot be changed once initialized. (Exception from HRESULT: 0x80010119)
Source=Cannot evaluate the exception source
StackTrace: Cannot evaluate the exception stack trace
This is the first thing that happens in the application App.xaml.cs
public partial class App : Application
{
public App()
{
InitVS myApp;
myApp = new InitVS();
}
//More code
}
public class InitVS
{
[DllImport("Ole32.dll",
ExactSpelling = true,
EntryPoint = "CoInitializeSecurity",
CallingConvention = CallingConvention.StdCall,
SetLastError = false,
PreserveSig = false)]
private static extern void CoInitializeSecurity(
IntPtr pVoid,
int cAuthSvc,
IntPtr asAuthSvc,
IntPtr pReserved1,
uint dwAuthnLevel,
uint dwImpLevel,
IntPtr pAuthList,
uint dwCapabilities,
IntPtr pReserved3);
public InitVS()
{
//Error happens here
CoInitializeSecurity(IntPtr.Zero,
-1,
IntPtr.Zero,
IntPtr.Zero,
(uint)RpcAuthnLevel.PktPrivacy,
(uint)RpcImpLevel.Impersonate,
IntPtr.Zero,
(uint)EoAuthnCap.DynamicCloaking,
IntPtr.Zero);
}
}
What makes me most confused is that it works in VS2013 (haven't tried VS2015). We use Visual Studio Professional 2017 and Visual Studio Professional 2013.
I haven't really found any relating information. There is a ton about DLL import ofc but can't find anything that VS2017 does anything strange, or VS2013 for that mather.
User contributions licensed under CC BY-SA 3.0