LegacyWrapper icon indicating copy to clipboard operation
LegacyWrapper copied to clipboard

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

Open MrPG8 opened this issue 6 years ago • 10 comments

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

MrPG8 avatar Jul 24 '19 16:07 MrPG8

Which version of LegacyWrapper did you use?

zalintyre avatar Jul 25 '19 20:07 zalintyre

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 <TFunction> must be public'.

stevetiger03 avatar Feb 28 '20 16:02 stevetiger03

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

zalintyre avatar Mar 02 '20 23:03 zalintyre

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.

MrPG8 avatar Mar 03 '20 10:03 MrPG8

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?

covillia avatar Mar 30 '22 19:03 covillia

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

zalintyre avatar Mar 30 '22 20:03 zalintyre

[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 avatar Mar 30 '22 20:03 covillia

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

covillia avatar Mar 31 '22 15:03 covillia

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?

MrPG8 avatar Mar 31 '22 16:03 MrPG8

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

covillia avatar Mar 31 '22 17:03 covillia