none
Could not load file or assembly - The system cannot find the file specified

    Question

  • Hi,

    I'm trying to write a powershell script to control Lync.  I'm calling

    Import-module "C:\Lync\Microsoft.Lync.Model.dll" but I get the error:
    Could not load file or assembly 'Microsoft.Office.Uc, Version=4.0.7577.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
     dependencies. The system cannot find the file specified.

    Microsoft.Office.Uc.Dll is in the C:\Lync\ directory.  Microsoft.Lync.Model.dll is part of the SDK.  If I install the SDK and call import-module from the SDK directory, everything works fine.  But, I need to avoid installing the SDK. 

    Is there somewhere else that powershell is looking for Microsoft.Office.Uc.dll?

    Thank you!

    Wednesday, February 08, 2012 1:14 AM

Answers

  • I registered all the DLL's in the SDK folder and it worked successfully.  Thanks all for the help.  BTW - this works with both:[Reflection.Assembly]::LoadFile('C:\Lync\Microsoft.Lync.Model.DLL') | out-null     

    Or

    import-module "C:\Lync\Microsoft.Lync.Model.DLL"

    Wednesday, February 08, 2012 2:18 PM
  • To be able to access the namespaces, classes, and, types in the .dll you need to use Reflection, not, Import-Module.  Modules, in Powershell, are different from regular .dll files in .NET.  This link is  great starting point:

    http://www.dougfinke.com/blog/index.php/2010/08/29/how-to-load-net-assemblies-in-a-powershell-session/

    • Marked as answer by Teodelas Wednesday, February 08, 2012 2:47 PM
    Wednesday, February 08, 2012 1:39 AM
  • I think the challenge here is to get all dependencies which are the .dll needs.
    If you install the SDK, the dlls may registered into the Global Assembly Cache or (GAC). So they got found.
    So you have pobably to figure out which rigistrations you have to make to use the DLLs.
    At last Step you can make a PowerShell Module from the DLLs with cmdlet New-ModuleManifest.


    Please click “Mark as Answer” if my post answers your question and click Vote as Help if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als Hilfreich und Beiträge die deine Frage ganz oder teilweise beantwortet haben als Antwort.
    My PowerShell Blog http://www.admin-source.info

    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace" "


    • Edited by Peter Kriegel Wednesday, February 08, 2012 6:55 AM
    • Marked as answer by Teodelas Wednesday, February 08, 2012 2:47 PM
    Wednesday, February 08, 2012 6:48 AM

All replies

  • To be able to access the namespaces, classes, and, types in the .dll you need to use Reflection, not, Import-Module.  Modules, in Powershell, are different from regular .dll files in .NET.  This link is  great starting point:

    http://www.dougfinke.com/blog/index.php/2010/08/29/how-to-load-net-assemblies-in-a-powershell-session/

    • Marked as answer by Teodelas Wednesday, February 08, 2012 2:47 PM
    Wednesday, February 08, 2012 1:39 AM
  • Thanks Will.  Oddly enough, Import-Module works fine as long as I have the Lync SDK installed.

    So, with the Lync SDK installed, this works:
    [Reflection.Assembly]::LoadFile('C:\Lync\Microsoft.Lync.Model.DLL') | out-null      
    $client = [Microsoft.Lync.Model.LyncClient]::GetClient()

    With the Lync SDK not installed (another test machine) this does not work:
    [Reflection.Assembly]::LoadFile('C:\Lync\Microsoft.Lync.Model.DLL') | out-null      
    $client = [Microsoft.Lync.Model.LyncClient]::GetClient()Exception calling "GetClient" with "0" argument(s): "The type initializer for 'Microsoft.Lync.Model.LyncClient' threw an exception."
    At D:\update-presence.ps1:2 char:55
    + $client = [Microsoft.Lync.Model.LyncClient]::GetClient <<<< ()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    • Edited by Teodelas Wednesday, February 08, 2012 2:25 AM
    Wednesday, February 08, 2012 2:06 AM
  • I think the challenge here is to get all dependencies which are the .dll needs.
    If you install the SDK, the dlls may registered into the Global Assembly Cache or (GAC). So they got found.
    So you have pobably to figure out which rigistrations you have to make to use the DLLs.
    At last Step you can make a PowerShell Module from the DLLs with cmdlet New-ModuleManifest.


    Please click “Mark as Answer” if my post answers your question and click Vote as Help if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als Hilfreich und Beiträge die deine Frage ganz oder teilweise beantwortet haben als Antwort.
    My PowerShell Blog http://www.admin-source.info

    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace" "


    • Edited by Peter Kriegel Wednesday, February 08, 2012 6:55 AM
    • Marked as answer by Teodelas Wednesday, February 08, 2012 2:47 PM
    Wednesday, February 08, 2012 6:48 AM
  • Good to know. Now you've got me curious as to what .dll's can be loaded in this fashion.
    Wednesday, February 08, 2012 1:04 PM
  • I registered all the DLL's in the SDK folder and it worked successfully.  Thanks all for the help.  BTW - this works with both:[Reflection.Assembly]::LoadFile('C:\Lync\Microsoft.Lync.Model.DLL') | out-null     

    Or

    import-module "C:\Lync\Microsoft.Lync.Model.DLL"

    Wednesday, February 08, 2012 2:18 PM
  • registering the DLL and putting it in the GAC are not the same.
     
    really you'd just need to know the order in which they are loaded so that
    you could simulate that order in your script.. how you'd figure that out, im
    not sure...
     
     

    Justin Rich
    http://jrich523.wordpress.com
    PowerShell V3 Guide (Technet)
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, February 08, 2012 2:48 PM
  • Hi Adoyt,

                         I'm getting the same exception error when i use the Getclient() method. Have you figured what is the issue? I'm trying this on the computer that has Lync client SDK installed. Also in my case there is no lync on premises server but connected to  Lync online  .


    • Edited by chkar Thursday, February 23, 2012 12:37 AM
    Thursday, February 23, 2012 12:17 AM