Skip to content

AddReference FileNotFoundException #1077

Closed

Description

@lzw-all-in

Environment

  • Pythonnet version: 2.4.0
  • Python version: 3.7
  • Operating System: Windows10

Details

clr.FindAssembly("VcClient")

it output:

'D:\\home\\lzw\\VcClient.dll'

but when I AddReference in this path it report exception:

clr.AddReference("D:\\home\\lzw\\VcClient.dll")

---------------------------------------------------------------------------
FileNotFoundException                     Traceback (most recent call last)
<ipython-input-43-045a91f26209> in <module>
----> 1 clr.AddReference("D:\\home\\lzw\\VcClient.dll")

FileNotFoundException: Unable to find assembly 'D:\home\lzw\VcClient.dll'.
   at Python.Runtime.CLRModule.AddReference(String name)

Activity

  1. filmor commented on Mar 4, 2020

    @filmor
    Member

    clr.AddReference("VcClient") should work. If it doesn't, please ask on the mailing list or on StackOverflow, this is not a support forum.

  2. lostmsu commented on Mar 4, 2020

    @lostmsu
    Member

    @filmor this might actually be a bug fixed in #1076 : it is possible, that "VcClient.dll" is either not a .NET DLL, or has wrong processor architecture, or does not have all its dependencies satisfied. In that case current implementation of AddReference always throws FileNotFoundException.

  3. lostmsu commented on Mar 4, 2020

    @lostmsu
    Member

    @lzw-all-in you might try to do

    import clr
    from System.Reflection import Assembly
    Assembly.LoadFrom("D:\\home\\lzw\\VcClient.dll")

    and see what exception you will get.

  4. lzw-all-in commented on Mar 4, 2020

    @lzw-all-in
    Author

    @lostmsu Thank you .
    It report exception like this :
    It looks like a support problem. But anyway Thanks a lot.

    ---------------------------------------------------------------------------
    NotSupportedException                     Traceback (most recent call last)
    NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
    
    The above exception was the direct cause of the following exception:
    
    FileLoadException                         Traceback (most recent call last)
    <ipython-input-3-cd28dedc6753> in <module>
    ----> 1 Assembly.LoadFrom("D:\\home\\lzw\\VcClient.dll")
    
    FileLoadException: Could not load file or assembly 'file:///D:\home\lzw\VcClient.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
       at System.Reflection.Assembly.LoadFrom(String assemblyFile)
    
  5. lzw-all-in commented on Mar 16, 2020

    @lzw-all-in
    Author

    @lostmsu Finally I finish this problem use Assembly.UnsafeLoadFrom(...). Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions