Could not load file or assembly 'EntityFramework' when starting a process with UseShellExecute = False

0

When I start a console app from an asp.net application and set UseShellExecute = False, I get the error:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An attempt was made to reference a token that does not exist. (Exception from HRESULT: 0x800703F0)

But when I start it with UseShellExecute = True, it works. Both the asp.net and the console app are using .net 4.6.1. The EntityFramework.dll and EntityFramework.SqlServer.dll are in the same folder as the console app.

I have tried everything and so far cannot get rid of the error. I prefer to UseShellExecute = False so that I can redirect the output to the asp.net app. It appears that it cannot find the dlls but it should since it is the same folder.

Here is a sample of the code I am using:

     Dim filename As String = "C:\apps\test.exe"
        Dim filepath As String = Path.GetDirectoryName(filename)


        Dim proc = New Process() With {
        .StartInfo = New ProcessStartInfo() With {
        .FileName = filename,
        .WorkingDirectory = filepath,
        .UseShellExecute = False,
        .RedirectStandardOutput = True,
        .RedirectStandardError = True,
        .CreateNoWindow = True
        }
   }
asp.net
vb.net
entity-framework
asked on Stack Overflow Nov 2, 2016 by cyberdog

1 Answer

0

After much debugging it seems to be a permissions issue. I did not think this was an issue before because the asp.net is using windows auth with impersonation and the userid has admin rights on the machine. But I guess it has something to do with the application pool identity. If I change it to a user account with higher permissions, then the above code works. I did read somewhere else that if you add .Domain, .User, .Password attributes to the above code it still doesn't work unless the app pool identity is the same user. So I guess I am stuck with just forgetting about redirecting the output and just use UseShellExecute = True instead.

answered on Stack Overflow Nov 3, 2016 by cyberdog

User contributions licensed under CC BY-SA 3.0