Search code examples
c#c#-3.0pervasive

Additional information: No se puede cargar el archivo o ensamblado 'BtLib.dll' ni una de sus dependencias


I have the following code.

 public CuentasCobrarBL(string rutaDatos)
        {
            rutaDirec = new CompanyBL(rutaDatos).rutaDirectorio;
            CompanyBL companybl = new CompanyBL(rutaDatos);
            Compania compania =  companybl.CargarCompania();
}




public ilimitada.Dominio.Pervasive.SCI.Core.Entidades.Compania CargarCompania()
        {
            ilimitada.Dominio.Pervasive.SCI.Core.Entidades.Compania companium = null;
            using (IPervasive<ilimitada.Dominio.Pervasive.SCI.Core.DAO.Estructuras.Compania> pervasive = BtrieveDataProvider<ilimitada.Dominio.Pervasive.SCI.Core.DAO.Estructuras.Compania>.Create(this.rutaDirectorio, 999))
            {
                //    pervasive.DataBuffer = new ilimitada.Dominio.Pervasive.SCI.Core.DAO.Estructuras.Compania();
                //    int num = (ushort)Marshal.SizeOf<ilimitada.Dominio.Pervasive.SCI.Core.DAO.Estructuras.Compania>(new ilimitada.Dominio.Pervasive.SCI.Core.DAO.Estructuras.Compania());
                //    if (pervasive.Open(OpenMode.Normal))
                //    {
                //        if (pervasive.GetFirst())
                //        {
                //            companium = CompaniaCV.ConvertirEstructuraEnObjeto(pervasive.DataBuffer);
                //        }
                //    }
            }
            return companium;
        }

The using line is throwing me this exception.

Additional information: No se puede cargar el archivo o ensamblado 'BtLib.dll' ni una de sus dependencias. No se puede encontrar el módulo especificado.

The BRetrieverDataProvider file is this:

using BtLib;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace ilimitada.AccesoDatos.Pervasive.Btrieve
{
    public class BtrieveDataProvider<T> : IPervasive<T>, IDisposable
    where T : class
    {
        private static IUnityContainer container;

        private short keyBufLen;

        private ushort structSize;

        private IntPtr pointer;

        private byte[] positionBlock;

        private byte[] keyBuffer;

        private string bufferName;

        private bool isDisposed;

        private LockBias lockbias;

        public T DataBuffer
        {
            get;
            set;
        }

        public short KeyNumber
        {
            get;
            set;
        }

        public short Status
        {
            get;
            set;
        }

        public BtrieveDataProvider(string fullFilePath, ushort structSize)
        {
            this.bufferName = fullFilePath;
            this.keyBuffer = Encoding.ASCII.GetBytes(this.bufferName);
            this.keyBuffer = new byte[255];
            byte[] bytes = Encoding.ASCII.GetBytes(this.bufferName);
            Array.Copy(bytes, this.keyBuffer, (int)bytes.Length);
            this.positionBlock = new byte[128];
            this.keyBufLen = 128;
            this.structSize = structSize;
            this.pointer = IntPtr.Zero;
            this.KeyNumber = 0;
            this.Status = -1;
            this.lockbias = LockBias.NoLock;
        }

        public void AbortTransaction()
        {
            byte[] numArray = new byte[128];
            byte[] bytes = Encoding.ASCII.GetBytes(this.bufferName);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.AbortTrans, numArray, this.pointer, ref this.structSize, bytes, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public void BeginTransaction(bool concurrent)
        {
            byte[] numArray = new byte[128];
            byte[] bytes = Encoding.ASCII.GetBytes(this.bufferName);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            if (!concurrent)
            {
                this.Status = Native.BtrCall(Operation.BeginTrans, numArray, this.pointer, ref this.structSize, bytes, this.keyBufLen, this.KeyNumber);
            }
            else
            {
                this.Status = Native.BtrCall(Operation.BeginConCurrentTransaction, numArray, this.pointer, ref this.structSize, bytes, this.keyBufLen, this.KeyNumber);
            }
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public void Close()
        {
            this.keyBuffer = Encoding.ASCII.GetBytes(this.bufferName);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.Close, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public static IPervasive<T> Create(string fullFilePath, ushort structSize)
        {
            BtrieveDataProvider<T>.container = new UnityContainer();
            BtrieveDataProvider<T>.container.AddNewExtension<Interception>();
            IUnityContainer unityContainer = BtrieveDataProvider<T>.container;
            InjectionMember[] interceptor = new InjectionMember[] { new Interceptor<InterfaceInterceptor>(), new InterceptionBehavior<LoggingInterceptionBehavior>(), null };
            object[] objArray = new object[] { fullFilePath, structSize };
            interceptor[2] = new InjectionConstructor(objArray);
            unityContainer.RegisterType<IPervasive<T>, BtrieveDataProvider<T>>(interceptor);
            return BtrieveDataProvider<T>.container.Resolve<IPervasive<T>>(new ResolverOverride[0]);
        }

        public bool Create(IntPtr pointerStructure, ushort size)
        {
            this.Status = Native.BtrCall(Operation.Create, this.positionBlock, pointerStructure, ref size, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool Delete()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.Delete, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 8)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public void Dispose()
        {
            if (!this.isDisposed)
            {
                try
                {
                    if (BtrieveDataProvider<T>.container != null)
                    {
                        BtrieveDataProvider<T>.container.Dispose();
                    }
                    this.isDisposed = true;
                    this.Close();
                }
                catch (System.Exception exception)
                {
                }
            }
        }

        public void EndTransaction()
        {
            byte[] numArray = new byte[128];
            byte[] bytes = Encoding.ASCII.GetBytes(this.bufferName);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.EndTrans, numArray, this.pointer, ref this.structSize, bytes, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public void FinishtLockRecord()
        {
            this.lockbias = LockBias.NoLock;
        }

        public void GetDirect()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.GetDirect, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public bool GetEqual(string condition)
        {
            this.keyBuffer = Encoding.Default.GetBytes(condition);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetEqual, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 4)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetFirst()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetFirst, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetGreater(string condition)
        {
            this.keyBuffer = Encoding.Default.GetBytes(condition);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetGreater, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetGreaterOrEqual(string condition)
        {
            this.keyBuffer = Encoding.Default.GetBytes(condition);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetGreaterOrEqual, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetLast()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetLast, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetLessThan(string condition)
        {
            this.keyBuffer = Encoding.Default.GetBytes(condition);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetLessThan, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetLessThanOrEqual(string condition)
        {
            this.keyBuffer = Encoding.Default.GetBytes(condition);
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetLessThanOrEqual, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool GetNext()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetNext, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 8 && this.Status != 9)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public void GetPosition()
        {
            ushort num = 4;
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.GetPosition, this.positionBlock, this.pointer, ref num, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 8)
            {
                throw new BtrieveException(this.Status);
            }
        }

        public bool GetPrevious()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Native.AddLockBias(Operation.GetPrevious, this.lockbias), this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 8 && this.Status != 9 && this.Status != 60 && this.Status != 62 && this.Status != 64)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public int GetStat(BtrieveStatistic typeStatistic)
        {
            short num = 0;
            int nroReg = 0;
            byte[] numArray = new byte[128];
            TypeCreate typeCreate = new TypeCreate();
            ushort num1 = (ushort)Marshal.SizeOf<TypeCreate>(typeCreate);
            IntPtr intPtr = Marshal.AllocCoTaskMem((int)num1);
            Marshal.StructureToPtr<TypeCreate>(typeCreate, intPtr, true);
            num = Native.BtrCall(Operation.Stat, this.positionBlock, intPtr, ref num1, numArray, this.keyBufLen, this.KeyNumber);
            if (num == 0)
            {
                Marshal.PtrToStructure<TypeCreate>(intPtr, typeCreate);
                switch (typeStatistic)
                {
                    case BtrieveStatistic.RecordNumber:
                    {
                        nroReg = typeCreate.NroReg;
                        break;
                    }
                    case BtrieveStatistic.KeyNumber:
                    {
                        nroReg = typeCreate.IndexCount;
                        break;
                    }
                    case BtrieveStatistic.RecordLength:
                    {
                        nroReg = typeCreate.RecLength;
                        break;
                    }
                    case BtrieveStatistic.SegmentNumber:
                    {
                        nroReg = (int)typeCreate.Keys.Length;
                        break;
                    }
                }
            }
            Marshal.FreeCoTaskMem(intPtr);
            if (num != 0)
            {
                throw new BtrieveException(num);
            }
            return nroReg;
        }

        public bool Insert()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.Insert, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public bool Open(OpenMode openMode = 0)
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            int num = 0;
            do
            {
                this.Status = Native.BtrCall(Operation.Open, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, (short)openMode);
                num++;
            }
            while (num <= 3 && this.Status == 3012);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 12)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }

        public void StartLockMultiRecord()
        {
            this.lockbias = LockBias.MultiNoWait;
        }

        public void StartLockRecord()
        {
            this.lockbias = LockBias.SingleNoWait;
        }

        public bool Update()
        {
            this.pointer = Marshal.AllocCoTaskMem((int)this.structSize);
            Marshal.StructureToPtr<T>(this.DataBuffer, this.pointer, true);
            this.Status = Native.BtrCall(Operation.Update, this.positionBlock, this.pointer, ref this.structSize, this.keyBuffer, this.keyBufLen, this.KeyNumber);
            Marshal.PtrToStructure<T>(this.pointer, this.DataBuffer);
            Marshal.FreeCoTaskMem(this.pointer);
            if (this.Status != 0 && this.Status != 8)
            {
                throw new BtrieveException(this.Status);
            }
            return this.Status == 0;
        }
    }
}

If I compile the solution is compiled without problems, the dll is put on the bin folder, but it looks like it cant be found by the program.

Help please.


Solution

  • Is your app launching from the bin directory? if not, you need to copy that library to the directory where the executable file is located.