CodefoundryDE / LegacyWrapper

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
MIT License
79 stars 20 forks source link

ASP.NET MVC - The system cannot find the file specified #22

Open MrPG8 opened 4 years ago

MrPG8 commented 4 years ago

I am trying to call a 32-bit DLL from an asp.net mvc website (which is running in a 64-bit application pool), but I keep getting this exception: "The system cannot find the file specified".

I am certain I'm doing something wrong, could you please point me into the right direction?

I'm using the sample code provided:

namespace Web.Sandbox
{
    [LegacyDllImport("User32.dll")]
    public interface IUser32Dll : IDisposable
    {
        [LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
        int GetSystemMetrics(int nIndex);
    }

    public class SandboxWrapper
    {
        public static void Test()
        {
            IWrapperConfig configuration = WrapperConfigBuilder.Create().TargetArchitecture(TargetArchitecture.X86).Build();

            using (var client = WrapperProxyFactory<IUser32Dll>.GetInstance(configuration))
            {
                int x = client.GetSystemMetrics(0);
                int y = client.GetSystemMetrics(1);
            }
        }
    }
}

Stack trace: at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at LegacyWrapperClient.Transport.PipeConnector..ctor(IFormatter formatter, IWrapperProcessStarter wrapperProcessStarter, PipeStreamFactory pipeStreamFactory, PipeToken pipeToken) in D:\Programmierung\CSharp\LegacyWrapper\LegacyWrapperClient\Transport\PipeConnector.cs:line 60 at DynamicInjectorf689774ad5234e388d4a1b8fc2720cdd(Object[] ) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.Planning.Targets.Target'1.ResolveWithin(IContext parent) at System.Linq.Enumerable.WhereSelectArrayIterator'2.MoveNext() at System.Linq.Buffer'1..ctor(IEnumerable'1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable'1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.Planning.Targets.Target'1.ResolveWithin(IContext parent) at System.Linq.Enumerable.WhereSelectArrayIterator'2.MoveNext() at System.Linq.Buffer'1..ctor(IEnumerable'1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable'1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) at Ninject.Activation.Context.ResolveInternal(Object scope) at Ninject.Activation.Context.Resolve() at Ninject.KernelBase.Resolve(IRequest request, Boolean handleMissingBindings) at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters) at LegacyWrapperClient.Client.WrapperProxyFactory1.CreateProxy() in D:\Programmierung\CSharp\LegacyWrapper\LegacyWrapperClient\Client\WrapperProxyFactory.cs:line 43

zalintyre commented 4 years ago

Which version of LegacyWrapper did you use?

stevetiger03 commented 4 years ago

I also experience the same issue, with version 3.0 (latest code). My sample app is WinForm, it also raised exception 'The provided interface type must be public'.

zalintyre commented 4 years ago

@stevetiger03 so, is your interface public? ;) This could also mean that the assembly containing the interface is not visible from your calling code.

MrPG8 commented 4 years ago

Sorry for the late reply, I did not get any notifications until 4 days ago.

As it turns out, the issue was caused by insufficient permissions. So the error message 'The system cannot find the file specified' was pretty accurate. If anyone else runs into issues like this, check your app permissions (and the DLLs). This issue is not caused by LegacyWrapper.

covillia commented 2 years ago

I'm not sure I understand what is happening. I'm having the same error message. I call the path directly i.e. "C:\Blah\Blahblah\Dis.dll" Do you mean check the securtiy permissions inthe context menu?

zalintyre commented 2 years ago

What is the actual error message you receive? Is your interface public?

covillia commented 2 years ago
[LegacyDllImport("C:\\CNCWorkbench\\Control\\CAN\\CanApi.dll")]
public interface IselImport : IDisposable
{
    [LegacyDllMethod(CallingConvention = CallingConvention.Winapi)]
    uint mctl_Initialize([MarshalAs(UnmanagedType.LPStr)] string szInitFile);
    uint mctl_Exit();
    uint mctl_Reset();
    uint mctl_Reference(uint dwAxis);
    uint mctl_GetStatus(ref MCTLSTATUS lpMCTLStatus, uint dwSize);
    uint mctl_GetAxisStatus(ref AXISSTATUS lpAxisStatus, uint dwSize);
    uint mctl_SetVelocity(ref MCTLVELOCITY lpMctlVelocity, uint dwSize);
    uint mctl_GetVelocity(ref MCTLVELOCITY lpMctlVelocity, uint dwSize);
    uint mctl_MoveAbs(ref AXISPOS lpAbsPos, uint dwSize);
    uint mctl_FastAbs(ref AXISPOS lpAbsPos, uint dwSize);
    uint mctl_GetPosition(ref AXISPOS lpPosition, uint dwSize);
}

Faults at the using here:

        using(var client = WrapperProxyFactory<IselImport>.GetInstance(m_WrapperConfig))
        {
            if (!TableStatus.fInitialized)
            {
                CurrentReturn = client.mctl_Initialize(m_iniFile);
covillia commented 2 years ago

It's the same error. "The System cannot find the file specified."

MrPG8 commented 2 years ago

Well, it was a long time ago, but it pretty much comes down to either the file can not be found (in your case that is not likely as you specified the full path) or insufficient rights. Have you tried running your program as administrator or making sure the file can be accessed by your program or the .dll isn't blocked by windows?

covillia commented 2 years ago

Full Control permision on all folders and files on the Application path an the API path. Running as administrator on the application.

Is there any other way you can think of That windows would block the file?

The API works in DLLImport while on 32-bit, But I have another SDK that is 64-bit