代码之家  ›  专栏  ›  技术社区  ›  Luis Valencia

附加信息:无se puede cargar el archivo o ensambado‘BtLib。dll‘ni una de sus依赖性

  •  0
  • Luis Valencia  · 技术社区  · 9 年前

    我有以下代码。

     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;
            }
    

    using行向我抛出了这个异常。

    附加信息:No se puede cargar el archivo o ensamblado 'BtLib。dll没有sus依赖性。没有任何问题 特别是mdulo。

    BRetrieverDataProvider文件如下:

    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;
            }
        }
    }
    

    如果我编译解决方案时没有问题,dll会放在bin文件夹中,但看起来程序找不到它。

    请帮忙。

    1 回复  |  直到 9 年前
        1
  •  1
  •   jcvegan    9 年前

    您的应用程序是否从 bin 目录 如果没有,则需要将该库复制到可执行文件所在的目录。