1
votes

I'm trying to use dblinq in my IronPython application but am having some problems getting started. When trying to import dblinq classes,using clr.AddReference() it does not seem to see dblinq.

I can build but not access the library

import clr
clr.AddReference("DbLinq")
clr.AddReference("System.Data.Linq")
from System.Data.Linq import DataContext

exit = raw_input("press any key to quit")

1: My dblinq source is in a subfolder called Resources

clr.AddReferenceToFileAndPath("Resources/DbLinq.dll") => file not found

clr.AddReference("DbLinq") => could not add reference to dblinq

clr.AddReferenceToFileAndPath("C:/Development/DBLinq2/Dblinq.dll" => success

but still cannot use the classes using from DbLinq import ...

Solution

    import clr

   clr.AddReferenceToFileAndPath("%s\Resources\DbLinq.dll" %os.getcwd())
    clr.AddReference("DbLinq")
    from Npgsql import *
    from DbLinq import Data
1
Maybe you are missing some other dependencies. Try running Dependency Walker (dependencywalker.com) on DbLinq.dll to see if that yields something interesting... - ChristopheD
Hmm, IESHIMS.dll is one of the dependencies which you should not worry about... Did you run dependency walker on Resources/DbLinq.dll (you should) or C:\Development\DBLinq2... (that directory might contain other dll's which are needed in the Resource directory) - ChristopheD
Did it on both, Resources contains all the files that Development\Dblinq2 does - Antarr Byrd
so are you not able to use/import stock dblinq types or code from you based on that? Have you tried adding your dblinq directory to the path? import sys sys.path.append(r"C:\Temp\DbLinq-0.20.1") - Simon Opelt
you appended the dblinq.dll itself to the path .. could you try that again pointing to the folder containing all the dlls coming with dblinq? and you still need to clr.AddReference("DbLinq") - Simon Opelt

1 Answers

2
votes

For libraries like DbLinq that come with dependencies or are split into several DLLs/modules you can programmatically add their location to allow the runtime to find all required files.

import sys
sys.path.append(r"C:\Temp\DbLinq-0.20.1")

You can then reference all required assemblies as usual:

clr.AddReference("DbLinq")

If there is one primary assembly you can also use clr.AddReferenceToFileAndPath (with an absolute path) which will implicitly add the referenced assemblies location to the path.

clr.AddReference(r"C:\Temp\DbLinq-0.20.1\DbLinq.dll")