accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.49k stars 1.99k forks source link

Accord.Video.FFMPEG in IIS? -Could not load file or assembly #428

Open RonSijm opened 7 years ago

RonSijm commented 7 years ago

I'm trying to get Accord.Video.FFMPEG to work in IIS, but I keep getting the error:

Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I've tried a bunch of different things, like copying the Accord.Video.FFMPEG files and other codec files to system32, and SysWOW64 - tried compiling both x86 and x64, debug and release, adding config to my web.config, but nothing seems to work.

I've created 2 sample projects. One I made as a winform, which just contains the following:

var reader = new VideoFileReader();
reader.Open(@"C:\Camarilla\Video\vid.mp4");

var framecount = reader.FrameCount;
var frameRate = reader.FrameRate;

Which worked instantly after adding the Accord.Video.FFMPEG nuget.

I then made a new ASP.Net Web Application, chose the Web API template, configured it to run under normal IIS (instead of IIS express) added the Accord.Video.FFMPEG nuget and tried to run the application.

This is the full log:

Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Accord.Video.FFMPEG' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Accord.Video.FFMPEG
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: Accord.Video.FFMPEG | Domain ID: 4
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/Video/VideoTest.Web/Videotest.Web/Videotest.Web/
LOG: Initial PrivatePath = C:\Video\VideoTest.Web\Videotest.Web\Videotest.Web\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Video\VideoTest.Web\Videotest.Web\Videotest.Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/videotest.web/93651fd8/923131f1/Accord.Video.FFMPEG.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/videotest.web/93651fd8/923131f1/Accord.Video.FFMPEG/Accord.Video.FFMPEG.DLL.
LOG: Attempting download of new URL file:///C:/Video/VideoTest.Web/Videotest.Web/Videotest.Web/bin/Accord.Video.FFMPEG.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Stack Trace:

[BadImageFormatException: Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49

[ConfigurationErrorsException: Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +772
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +259
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +163
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +230
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +76
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +343
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +176
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +734

[HttpException (0x80004005): Could not load file or assembly 'Accord.Video.FFMPEG' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +716

I've added the two sample projects as attachments: videoTest.zip

Can someone please tell me how to solve this? And how to get this library running in IIS? Or if someone could post a sample project that does working under IIS, that'd be great.

Thanks!

I'm using Visual Studio 2015 community edition update 3, and my computer is running Windows 10, x64. The actual application that I want this to work in will run on Windows Server 2012 R2, AMD64

stigvoss commented 7 years ago

Hello,

It seems your project is configured to compile as x86. By default IIS runs code in x64 mode and you have to configure your IIS to run x86 code. This can be done by going to the corresponding application pool and entering Advanced Settings. Here you will find an "Enable 32-Bit Appplications" options.

The other option is the get your code to compile as x64.

RonSijm commented 7 years ago

Hey,

Thanks for the quick reply - I might have left the configuration to x86 in the zip I've posted, but like I said, I've tried getting it to work in both debug and release, and also both x86 and x64, which did not help.

The winform project I just left it on Any CPU, (which would probably default to x64) which worked instantly.

cesarsouza commented 7 years ago

I think this is happening because the msbuild targets that is supposed to copy FFMPEG dlls to the output folder of the application does not work with web applications.

In order to use Accord.Video.FFMPEG, it is necessary to copy the native FFMPEG .dlls (that normally should be present inside the directory /packages/Accord.Video.FFMPEG/build if you installed using NuGet) to the same folder where Accord.Video.FFMPEG.dll resides.

I am not completely sure how this is set up in web projects. But without this, indeed one would get the "Could not load file or assembly" errors as seen above.

Also, note that since 2 releases ago Accord.NET now has 64-bit versions of the FFMPEG dlls, but you might have to install them explicitly by choosing the Accord.Video.FFMPEG.x64 package in the NuGet browser.

Regards, Cesar

AlexaHLE commented 7 years ago

I'm seeing a similar issue to what @RonSijm is seeing. I have an x86 project and IIS is configured to have 32-bit applications enabled. It looks like the ffmpeg .dlls @cesarsouza mentioned are being copied over.

I've also noticed that if I change the target framework of the project to 3.5 I no longer get the error. I saw in a few similar issues that installing the x86 2015 C++ redistributables solves the 3.5 dependency. I'm using Visual Studio 2017, and the 2017 redistributable I have is v14.11.25325, so the 2015 installer fails because it thinks a higher version of 14.* is already installed.

I tried uninstalling the 2017 and installing the 2015, which causes me to get the following error instead:

Could not load file or assembly 'Accord.Video.FFMPEG.DLL' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

cesarsouza commented 7 years ago

Hi @AlexaHLE,

It should be possible to have both VS2015, VS2017, as well as both 2015 and 2017 C++ redistributables installed together at the same time. Note that the redistributables can be downloaded and installed separately from Visual Studio from https://www.microsoft.com/en-us/download/details.aspx?id=48145 and https://go.microsoft.com/fwlink/?LinkId=746572. Have you installed all of them?

Also, have you tried to create a 64-bit application and using Accord.Video.FFMPEG.x64 instead?

Regards, Cesar

AlexaHLE commented 7 years ago

Hi Cesar,

I have attempted to install them. I get the following from the 2015 installer: image

The log has the following:

[29C4:591C][2017-09-20T12:52:35]i108: Detected compatible package: vcRuntimeMinimum_x86, provider: Microsoft.VS.VC_RuntimeMinimumVSU_x86,v14, installed: {029DA848-1A80-34D3-BFC1-A6447BFC8E7F}, version: 14.11.25325, chained: {A2563E55-3BEC-3828-8D67-E5E8B9E8B675}
[29C4:591C][2017-09-20T12:52:35]i103: Detected related package: {029DA848-1A80-34D3-BFC1-A6447BFC8E7F}, scope: PerMachine, version: 14.11.25325.0, language: 0 operation: Downgrade
[29C4:591C][2017-09-20T12:52:35]i108: Detected compatible package: vcRuntimeAdditional_x86, provider: Microsoft.VS.VC_RuntimeAdditionalVSU_x86,v14, installed: {568CD07E-0824-3EEB-AEC1-8FD51F3C85CF}, version: 14.11.25325, chained: {BE960C1C-7BAD-3DE6-8B1A-2616FE532845}
[29C4:591C][2017-09-20T12:52:35]i103: Detected related package: {568CD07E-0824-3EEB-AEC1-8FD51F3C85CF}, scope: PerMachine, version: 14.11.25325.0, language: 0 operation: Downgrade

that version is the 2017 version: image

I have confirmed that if I uninstall the 2017 version, I can successfully run the 2015 installer. If I run the 2017 installer again, it replaces the 2015 version.

Unfortunately my application has other dependencies that require it to be 32 bit, but I tried using a 64 bit application and Accord.Video.FFMPEG.X64 just to see and it gets a similar error to the 32 bit version as seen below. There isn't a Accord.Video.FFMPEG.x64.3.7.0\lib\net35 folder so I can't try dropping the version.

Server Error in '/Test' Application.

Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[FileNotFoundException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +457
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +110
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
   System.Reflection.Assembly.Load(String assemblyString) +34
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +48

[ConfigurationErrorsException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +729
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +247
   System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +157
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +226
   System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +73
   System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +321
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +170
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +878

[HttpException (0x80004005): Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +525
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +124
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +700

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
devbratghosh commented 7 years ago

Does anybody find a working solution?

cesarsouza commented 7 years ago

Hi @devbratghosh,

Could you please try with the latest pre-release package (3.8.2-alpha) currently available in NuGet? This version should depend only on the VS2015 runtime, so at least it should make it easier to eliminate what should be the problem.

Then, please make sure your application is running in 64-bits mode (check Environment.Is64BitProcess and Environment.Is64BitOperatingSystem), and if so, download and install only Accord.Video.FFMPEG.x64 from NuGet (do not install Accord.Video.FFMPEG).

If you are still having the problem, please check the value for Directory.GetCurrentDirectory() and make sure the FFmpeg's dlls are contained in this folder. I suspect they aren't there, and that's the reason for the error.

Instead, try to adjust the PATH variable to include the directory where those .dlls are (normally in your Bin folder). For example, you may try to set it inside your process using something like...

string oldPath = Environment.GetEnvironmentVariable("Path");
Environment.SetEnvironmentVariable("Path", pathToFFmpegDlls + ";" + oldPath);

... maybe as soon as your process starts, or maybe just before attempting to use type from Accord.Video.FFmpeg.

Please let me know if it helps, Cesar

robertkx commented 6 years ago

I had the same issue with Accord.Video.FFMPEG.DLL

Could not load file or assembly

I removed "Accord.Video.FFMPEG" and install "Accord.Video.FFMPEG.x64 3.8.2-alpha"

then I got this error:

Could not load file or assembly 'Accord.Video.FFMPEG.x64' or one of its dependencies. An attempt was made to load a program with an incorrect format.

finally by setting "User the 64 bit version of IIS Express...." issue solved and dlls load correctly, without need to setting PATH variable.

image

Thanks @cesarsouza for clear comments.

quocdai92 commented 6 years ago

In order to use Accord.Video.FFMPEG, it is necessary to copy the native FFMPEG .dlls (that normally should be present inside the directory /packages/Accord.Video.FFMPEG/build if you installed using NuGet) to the same folder where Accord.Video.FFMPEG.dll resides.

As @cesarsouza said. I directly copy all dlls from /packages/Accord.Video.FFMPEG to the /bin folder. It worked correctly.

PrakashPaul commented 5 years ago

System.IO.FileNotFoundException: Could not load file or assembly 'Accord.Video.FFMPEG.x64.DLL' or one of its dependencies. The specified module could not be found. using Accord.Video.FFMPEG.x64.3.8.0 version. when deployed application in one win8 server IIS7.5 and copied below dll into application bin and system folder application worked fine. but failed in other server though configuration are same for server. not sure what I am missing. any help will be appreciated. image

toriqsagor commented 5 years ago

Hello, I'm trying to integrate in a 32 bit windows, but showing below problem. I've got only X64 bit dll. Is there any x86 bit dll for accord video file writer.

Could not load file or assembly 'Accord.Video.FFMPEG.DLL' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

This is huge burdening, couldn't find out Accod.video.ffmpeg.dll for 32 bit. Anyone can help me.

Thanks in advance By Toriqsagor

PrakashPaul commented 5 years ago

[image: image.png] manage nuget package-> search for Accord.Video.FFMPEG you have both 32 and 64

On Fri, Apr 5, 2019 at 5:13 AM toriqsagor notifications@github.com wrote:

Hello,

I'm trying to integrate in a 32 bit windows, but showing below problem. I've got only X64 bit dll. Is there any x86 bit dll for accord video file writer.

Could not load file or assembly 'Accord.Video.FFMPEG.DLL' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

This is huge burdening, couldn't find out Accod.video.ffmpeg.dll for 32 bit. Anyone can help me.

Thanks in advance By Toriqsagor

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/accord-net/framework/issues/428#issuecomment-480205774, or mute the thread https://github.com/notifications/unsubscribe-auth/AD1tTMrNLlBHKhVfV9F4l8x3HqKM3Yo0ks5vdxOigaJpZM4MBb8r .

-- Thanks and Regards Prakash Paul

toriqsagor commented 5 years ago

Thanks a lot PrakashPaul. I've got the points.

ghost commented 4 years ago

I have copied all the files to "bin" directory as mentioned by @PrakashPaul , set the project to x64 and deployed on trial MS Azure web app. But I'm still getting this error. Please help?

gnsharans commented 4 years ago

Microsoft visual c++ redistributable 2010,2012,2013,2015 x64,x86 Please install all these and then check, basically for some systems it's okay with 2015, for my system it worked after installing 2012 and 2013.... ..please do provide feedback if any one resolved by doing this.