System.AccessViolationException on Initialize

Description
I’m trying to use the Zoom Client SDK in a .NET 4.7.2 Web API. I’m trying to setup my wrapper as a Singleton so I’m instantiating it in the WebApiConfig.Register method but even here it won’t work (instantiating it inside the controller methods created a similar Exception).

Here is my code:

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            DebugLogService debugService = new DebugLogService();
            ZoomService zoomService = new ZoomService(debugService);
            Task<bool> initializeZoom = zoomService.InitializationAsync("...", "...");
            initializeZoom.Wait();
            bool result = initializeZoom.Result;
            debugService.Log($"result = {result}");
        }
    }

ZoomService.cs:

...
        public async Task<bool> InitializationAsync(string appKey, string appSecret)
        {
            try
            {
                var sdkInitialized = SdkInitialize();
                if (!sdkInitialized) return false;

                Initialized = await SdkAuthenticationAsync(appKey, appSecret);
            }
            catch (Exception)
            {
                Initialized = false;
            }

            return Initialized;
        }
...
        private bool SdkInitialize()
        {
            InitParam param = new InitParam
            {
                web_domain = "https://zoom.us",
                enable_log = true,
                
            };

            // This line throws System.AccessViolationException
            SDKError error = CZoomSDKeDotNetWrap.Instance.Initialize(param);

            return error == SDKError.SDKERR_SUCCESS;
        }

I’m assuming something is wrong in my setup, but I copied most of this from an existing working WPF solution. Any advice would be helpful.

Which Windows Client SDK version?
5.5.12509.0330
Assembly zoom_sdk_dotnet_wrap, Version=1.0.7575.37543

Device (please complete the following information):
Windows 10

Hey @tyler,

Thanks for using the dev forum!

Support for this is a little limited, but I can try and help. Is it possible you just need to add “ZOOM_SDK_DOTNET_WRAP.” before the InitParam and the CZoomSDKeDotNetWrap?

Thanks!
Michael

I simplified my code to just this as requested

        public static async void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            ZOOM_SDK_DOTNET_WRAP.InitParam param = new ZOOM_SDK_DOTNET_WRAP.InitParam
            {
                web_domain = "https://zoom.us",
                config_opts = { optionalFeatures = 1 << 5 },   // Using Zoom Customized UI
            };

            SDKError error = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.Initialize(param);
        }

I’m still getting the same exception. My guess is that the static instance sits outside of the memory space in MVC solutions.

I will note that I’m able to call the C++ SDK from a DLL import from inside my MVC application, so this seems to point to something in the way the memory space is setup in the C# wrapper.

I tried this as well

        [DllImport(@"test.dll", EntryPoint = "get_zoom_sdk_instance", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetZoomSdkInstance();

        public static async void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            IntPtr zoomSdkInstance = GetZoomSdkInstance();
            ZOOM_SDK_DOTNET_WRAP.InitParam param;
            unsafe
            {
                param = new ZOOM_SDK_DOTNET_WRAP.InitParam
                {
                    web_domain = "https://zoom.us",
                    config_opts = { optionalFeatures = 1 << 5 },   // Using Zoom Customized UI
                    res_instance = zoomSdkInstance.ToPointer(),
                };

                SDKError error = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.Initialize(param);
            }
        }

With this C++ method

    __declspec(dllexport) SDKInterfaceWrap* __stdcall get_zoom_sdk_instance() {
        return &SDKInterfaceWrap::GetInst();
    }

But I got the same error on initialize. Could it be the Initialize method in the C# wrapper is somehow handling memory incorrectly?

Sorry for the overload, but I figure more information is always better.

I confirmed the following code works inside a simple console application:

        [DllImport(@"test.dll", EntryPoint = "get_zoom_sdk_instance", CallingConvention = CallingConvention.StdCall)]
        public static extern IntPtr GetZoomSdkInstance();

        static void Main(string[] args)
        {
            IntPtr zoomSdkInstance = GetZoomSdkInstance();
            unsafe
            {
                ZOOM_SDK_DOTNET_WRAP.InitParam param = new ZOOM_SDK_DOTNET_WRAP.InitParam
                {
                    web_domain = "https://zoom.us",
                    config_opts = { optionalFeatures = 1 << 5 },   // Using Zoom Customized UI
                    res_instance = zoomSdkInstance.ToPointer(),
                };

                SDKError error = ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance.Initialize(param);
            }
        }

Some further investigation: looks like it’s not the Initialize method in the C# wrapper. Any reference to doing anything to ZOOM_SDK_DOTNET_WRAP.CZoomSDKeDotNetWrap.Instance throws that AccessViolationException. Looks like however the static instance is setup in the wrapper causes issues in MVC.

Hey @tyler,

I see. Is it possible you are not creating the static instance properly?

Thanks!
Michael

Hey @Michael_Condon, in my existing application there is no need to create the static instance as far as I’ve seen. Can you give me any example? In my WPF forms application where this is working it just starts using the static instance.

As far as I know in C# there is no need to “create a static instance” if you’re referring to instantiation. Or are you referring to something else that needs to be done?

Hey @tyler,

The reason you would make it static is to make the “Instance” a global singleton. So that there is always only one DotNetWrap and it is available whenever needed.

Michael

Do you have some sample code on how to do this?

Hey @tyler,

Yes but it would be the same code that is available in the C# wrapper demo. If that code does not work, it is likely an MVC issue.

Thanks!
Michael

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.