Exception raised attempting to access Lync.DeviceManager.AudioDevices - but not the Count property












0














Trying to set the active Lync Audio device to one of the available audio devices. Lync_Client.DeviceManager.AudioDevices.Count returns a number greater than 0 but statements like Lync_CLient.DeviceManager.AudioDevices[i] in a for loop from i = 0 to i < count or foreach (AudioDevice dev in Lync_Client.DeviceManager.AudioDevices) immediately raises an exception when run on Windows 10 PC - but not on Windows 7 PC. Windows 10 version produces an exception with the Message:
"Exception has been thrown by the target of an invocation.



Any suggestions? Could this be a privilege issue?



Below is the StackTrace:



...at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
...at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
...at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
...at Microsoft.Lync.Model.Internal.UCWCache.CreateUCW(Object source, CCOMInfo ccomInfo)
...at Microsoft.Lync.Model.Internal.UCWCache.GetITTargetNS(Object source)
...at Microsoft.Lync.Model.Internal.UCEnumerator`2.get_Current()
...at ...Microsoft.Lync.Model.Internal.UCEnumerator`2.System.Collections.Generic.IEnumerator<S>.get_Current()


The stack from here on out points to my code that attempts to access the Lync AudioDevices elements enumeration










share|improve this question





























    0














    Trying to set the active Lync Audio device to one of the available audio devices. Lync_Client.DeviceManager.AudioDevices.Count returns a number greater than 0 but statements like Lync_CLient.DeviceManager.AudioDevices[i] in a for loop from i = 0 to i < count or foreach (AudioDevice dev in Lync_Client.DeviceManager.AudioDevices) immediately raises an exception when run on Windows 10 PC - but not on Windows 7 PC. Windows 10 version produces an exception with the Message:
    "Exception has been thrown by the target of an invocation.



    Any suggestions? Could this be a privilege issue?



    Below is the StackTrace:



    ...at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
    ...at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
    ...at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
    ...at Microsoft.Lync.Model.Internal.UCWCache.CreateUCW(Object source, CCOMInfo ccomInfo)
    ...at Microsoft.Lync.Model.Internal.UCWCache.GetITTargetNS(Object source)
    ...at Microsoft.Lync.Model.Internal.UCEnumerator`2.get_Current()
    ...at ...Microsoft.Lync.Model.Internal.UCEnumerator`2.System.Collections.Generic.IEnumerator<S>.get_Current()


    The stack from here on out points to my code that attempts to access the Lync AudioDevices elements enumeration










    share|improve this question



























      0












      0








      0







      Trying to set the active Lync Audio device to one of the available audio devices. Lync_Client.DeviceManager.AudioDevices.Count returns a number greater than 0 but statements like Lync_CLient.DeviceManager.AudioDevices[i] in a for loop from i = 0 to i < count or foreach (AudioDevice dev in Lync_Client.DeviceManager.AudioDevices) immediately raises an exception when run on Windows 10 PC - but not on Windows 7 PC. Windows 10 version produces an exception with the Message:
      "Exception has been thrown by the target of an invocation.



      Any suggestions? Could this be a privilege issue?



      Below is the StackTrace:



      ...at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
      ...at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
      ...at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
      ...at Microsoft.Lync.Model.Internal.UCWCache.CreateUCW(Object source, CCOMInfo ccomInfo)
      ...at Microsoft.Lync.Model.Internal.UCWCache.GetITTargetNS(Object source)
      ...at Microsoft.Lync.Model.Internal.UCEnumerator`2.get_Current()
      ...at ...Microsoft.Lync.Model.Internal.UCEnumerator`2.System.Collections.Generic.IEnumerator<S>.get_Current()


      The stack from here on out points to my code that attempts to access the Lync AudioDevices elements enumeration










      share|improve this question















      Trying to set the active Lync Audio device to one of the available audio devices. Lync_Client.DeviceManager.AudioDevices.Count returns a number greater than 0 but statements like Lync_CLient.DeviceManager.AudioDevices[i] in a for loop from i = 0 to i < count or foreach (AudioDevice dev in Lync_Client.DeviceManager.AudioDevices) immediately raises an exception when run on Windows 10 PC - but not on Windows 7 PC. Windows 10 version produces an exception with the Message:
      "Exception has been thrown by the target of an invocation.



      Any suggestions? Could this be a privilege issue?



      Below is the StackTrace:



      ...at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
      ...at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
      ...at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
      ...at Microsoft.Lync.Model.Internal.UCWCache.CreateUCW(Object source, CCOMInfo ccomInfo)
      ...at Microsoft.Lync.Model.Internal.UCWCache.GetITTargetNS(Object source)
      ...at Microsoft.Lync.Model.Internal.UCEnumerator`2.get_Current()
      ...at ...Microsoft.Lync.Model.Internal.UCEnumerator`2.System.Collections.Generic.IEnumerator<S>.get_Current()


      The stack from here on out points to my code that attempts to access the Lync AudioDevices elements enumeration







      lync lync-2013 lync-client-sdk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 28 at 6:12









      Graham

      3,523123558




      3,523123558










      asked Oct 27 at 20:14









      T Moran

      34




      34
























          1 Answer
          1






          active

          oldest

          votes


















          0














          The problem is that Microsoft stop releasing the Lync Client SDK for Lync 2013 Client. Even though the SDK still works so the latest version of the Skype for Business Client, it is actually slowly breaking due to incompatibilities between the current Skype for Business client and the older Lync Client SDK.



          The AudioDevice area of the SDK is a one of the known areas of the SDK where the Client SDK is breaking. There is a workaround where you can drop down to the actual the raw COM interfaces that the Lync Client SDK uses and then use those COM objects directly get access to the API.



          You can escape the Lync Client SDK into the raw COM objects by accessing the "InnerObject" field of the Lync Client SDK object.



          eg:



              static bool SetClientAudioDevice(LyncClient client, string name)
          {
          var innerClient = (ILyncClient)client.InnerObject;
          var deviceManager = innerClient.DeviceManager;

          Console.WriteLine("Current audio device: [{0}]", client.DeviceManager.ActiveAudioDevice.Name);
          Console.WriteLine("Lync Client Audio Devices List:");
          var ok = false;
          foreach (var device in deviceManager.AudioDevices.OfType<Microsoft.Office.Uc.AudioDevice>())
          {
          Console.WriteLine(" AudioDevice: [{0}], Active[{1}], ID[{2}], IsCertified[{3}], Priority[{4}], Type[{5}]", device.Name, device.IsActive, device.Id, device.IsCertified, device.Priority, device.Type);

          if (device.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) >= 0)
          {
          Console.WriteLine(" Setting active device!");
          deviceManager.ActiveAudioDevice = device;
          ok = true;
          }
          }
          return ok;
          }


          As pointed out in the comments, you also have to add a reference to "Microsoft.Office.Uc" and also set the Embed InteropType to False.






          share|improve this answer























          • Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
            – T Moran
            Nov 9 at 15:07










          • Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
            – T Moran
            Nov 12 at 2:37












          • I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
            – Shane Powell
            Nov 12 at 3:14











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53025893%2fexception-raised-attempting-to-access-lync-devicemanager-audiodevices-but-not%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          The problem is that Microsoft stop releasing the Lync Client SDK for Lync 2013 Client. Even though the SDK still works so the latest version of the Skype for Business Client, it is actually slowly breaking due to incompatibilities between the current Skype for Business client and the older Lync Client SDK.



          The AudioDevice area of the SDK is a one of the known areas of the SDK where the Client SDK is breaking. There is a workaround where you can drop down to the actual the raw COM interfaces that the Lync Client SDK uses and then use those COM objects directly get access to the API.



          You can escape the Lync Client SDK into the raw COM objects by accessing the "InnerObject" field of the Lync Client SDK object.



          eg:



              static bool SetClientAudioDevice(LyncClient client, string name)
          {
          var innerClient = (ILyncClient)client.InnerObject;
          var deviceManager = innerClient.DeviceManager;

          Console.WriteLine("Current audio device: [{0}]", client.DeviceManager.ActiveAudioDevice.Name);
          Console.WriteLine("Lync Client Audio Devices List:");
          var ok = false;
          foreach (var device in deviceManager.AudioDevices.OfType<Microsoft.Office.Uc.AudioDevice>())
          {
          Console.WriteLine(" AudioDevice: [{0}], Active[{1}], ID[{2}], IsCertified[{3}], Priority[{4}], Type[{5}]", device.Name, device.IsActive, device.Id, device.IsCertified, device.Priority, device.Type);

          if (device.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) >= 0)
          {
          Console.WriteLine(" Setting active device!");
          deviceManager.ActiveAudioDevice = device;
          ok = true;
          }
          }
          return ok;
          }


          As pointed out in the comments, you also have to add a reference to "Microsoft.Office.Uc" and also set the Embed InteropType to False.






          share|improve this answer























          • Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
            – T Moran
            Nov 9 at 15:07










          • Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
            – T Moran
            Nov 12 at 2:37












          • I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
            – Shane Powell
            Nov 12 at 3:14
















          0














          The problem is that Microsoft stop releasing the Lync Client SDK for Lync 2013 Client. Even though the SDK still works so the latest version of the Skype for Business Client, it is actually slowly breaking due to incompatibilities between the current Skype for Business client and the older Lync Client SDK.



          The AudioDevice area of the SDK is a one of the known areas of the SDK where the Client SDK is breaking. There is a workaround where you can drop down to the actual the raw COM interfaces that the Lync Client SDK uses and then use those COM objects directly get access to the API.



          You can escape the Lync Client SDK into the raw COM objects by accessing the "InnerObject" field of the Lync Client SDK object.



          eg:



              static bool SetClientAudioDevice(LyncClient client, string name)
          {
          var innerClient = (ILyncClient)client.InnerObject;
          var deviceManager = innerClient.DeviceManager;

          Console.WriteLine("Current audio device: [{0}]", client.DeviceManager.ActiveAudioDevice.Name);
          Console.WriteLine("Lync Client Audio Devices List:");
          var ok = false;
          foreach (var device in deviceManager.AudioDevices.OfType<Microsoft.Office.Uc.AudioDevice>())
          {
          Console.WriteLine(" AudioDevice: [{0}], Active[{1}], ID[{2}], IsCertified[{3}], Priority[{4}], Type[{5}]", device.Name, device.IsActive, device.Id, device.IsCertified, device.Priority, device.Type);

          if (device.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) >= 0)
          {
          Console.WriteLine(" Setting active device!");
          deviceManager.ActiveAudioDevice = device;
          ok = true;
          }
          }
          return ok;
          }


          As pointed out in the comments, you also have to add a reference to "Microsoft.Office.Uc" and also set the Embed InteropType to False.






          share|improve this answer























          • Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
            – T Moran
            Nov 9 at 15:07










          • Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
            – T Moran
            Nov 12 at 2:37












          • I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
            – Shane Powell
            Nov 12 at 3:14














          0












          0








          0






          The problem is that Microsoft stop releasing the Lync Client SDK for Lync 2013 Client. Even though the SDK still works so the latest version of the Skype for Business Client, it is actually slowly breaking due to incompatibilities between the current Skype for Business client and the older Lync Client SDK.



          The AudioDevice area of the SDK is a one of the known areas of the SDK where the Client SDK is breaking. There is a workaround where you can drop down to the actual the raw COM interfaces that the Lync Client SDK uses and then use those COM objects directly get access to the API.



          You can escape the Lync Client SDK into the raw COM objects by accessing the "InnerObject" field of the Lync Client SDK object.



          eg:



              static bool SetClientAudioDevice(LyncClient client, string name)
          {
          var innerClient = (ILyncClient)client.InnerObject;
          var deviceManager = innerClient.DeviceManager;

          Console.WriteLine("Current audio device: [{0}]", client.DeviceManager.ActiveAudioDevice.Name);
          Console.WriteLine("Lync Client Audio Devices List:");
          var ok = false;
          foreach (var device in deviceManager.AudioDevices.OfType<Microsoft.Office.Uc.AudioDevice>())
          {
          Console.WriteLine(" AudioDevice: [{0}], Active[{1}], ID[{2}], IsCertified[{3}], Priority[{4}], Type[{5}]", device.Name, device.IsActive, device.Id, device.IsCertified, device.Priority, device.Type);

          if (device.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) >= 0)
          {
          Console.WriteLine(" Setting active device!");
          deviceManager.ActiveAudioDevice = device;
          ok = true;
          }
          }
          return ok;
          }


          As pointed out in the comments, you also have to add a reference to "Microsoft.Office.Uc" and also set the Embed InteropType to False.






          share|improve this answer














          The problem is that Microsoft stop releasing the Lync Client SDK for Lync 2013 Client. Even though the SDK still works so the latest version of the Skype for Business Client, it is actually slowly breaking due to incompatibilities between the current Skype for Business client and the older Lync Client SDK.



          The AudioDevice area of the SDK is a one of the known areas of the SDK where the Client SDK is breaking. There is a workaround where you can drop down to the actual the raw COM interfaces that the Lync Client SDK uses and then use those COM objects directly get access to the API.



          You can escape the Lync Client SDK into the raw COM objects by accessing the "InnerObject" field of the Lync Client SDK object.



          eg:



              static bool SetClientAudioDevice(LyncClient client, string name)
          {
          var innerClient = (ILyncClient)client.InnerObject;
          var deviceManager = innerClient.DeviceManager;

          Console.WriteLine("Current audio device: [{0}]", client.DeviceManager.ActiveAudioDevice.Name);
          Console.WriteLine("Lync Client Audio Devices List:");
          var ok = false;
          foreach (var device in deviceManager.AudioDevices.OfType<Microsoft.Office.Uc.AudioDevice>())
          {
          Console.WriteLine(" AudioDevice: [{0}], Active[{1}], ID[{2}], IsCertified[{3}], Priority[{4}], Type[{5}]", device.Name, device.IsActive, device.Id, device.IsCertified, device.Priority, device.Type);

          if (device.Name.IndexOf(name, StringComparison.InvariantCultureIgnoreCase) >= 0)
          {
          Console.WriteLine(" Setting active device!");
          deviceManager.ActiveAudioDevice = device;
          ok = true;
          }
          }
          return ok;
          }


          As pointed out in the comments, you also have to add a reference to "Microsoft.Office.Uc" and also set the Embed InteropType to False.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 3:16

























          answered Oct 29 at 16:25









          Shane Powell

          9,09023748




          9,09023748












          • Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
            – T Moran
            Nov 9 at 15:07










          • Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
            – T Moran
            Nov 12 at 2:37












          • I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
            – Shane Powell
            Nov 12 at 3:14


















          • Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
            – T Moran
            Nov 9 at 15:07










          • Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
            – T Moran
            Nov 12 at 2:37












          • I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
            – Shane Powell
            Nov 12 at 3:14
















          Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
          – T Moran
          Nov 9 at 15:07




          Tried this but getting an exception at LyncClient.GetClient. - "Could not load file or assembly 'Microsoft.Office.Uc, Version=15... or one of its dependencies. The system cannot find the file specified. " To compile I had to add a reference to Microsoft.Office.Uc. The path for the DLL points to an instance in Visual Studio 2017.
          – T Moran
          Nov 9 at 15:07












          Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
          – T Moran
          Nov 12 at 2:37






          Conflict between Lync.Model and Office.Uc solved. After "Adding a Reference" to Microsoft.Office.Uc, changed Embed InteropType to False. No longer getting the exception at GetClient and the solution provided by Shane Powell works.
          – T Moran
          Nov 12 at 2:37














          I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
          – Shane Powell
          Nov 12 at 3:14




          I forgot about the "Embed InteropType", I found the same that you have to set it to false as well.
          – Shane Powell
          Nov 12 at 3:14


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53025893%2fexception-raised-attempting-to-access-lync-devicemanager-audiodevices-but-not%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues