Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrPG8 opened this issue Jul 24, 2019 · 10 comments
Open

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

MrPG8 opened this issue Jul 24, 2019 · 10 comments

Comments

@MrPG8
Copy link

MrPG8 commented Jul 24, 2019

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
Copy link
Contributor

Which version of LegacyWrapper did you use?

@stevetiger03
Copy link

stevetiger03 commented Feb 28, 2020

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
Copy link
Contributor

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

@MrPG8
Copy link
Author

MrPG8 commented Mar 3, 2020

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
Copy link

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
Copy link
Contributor

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

@covillia
Copy link

[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
Copy link

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

@MrPG8
Copy link
Author

MrPG8 commented Mar 31, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants