C#指定的可执行文件不是此OS平台的有效应用程序 [英] C# The specified executable is not a valid application for this OS platform

查看:920
本文介绍了C#指定的可执行文件不是此OS平台的有效应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的学士学位制作一个视频共享应用程序(类似于youtube)(该项目以asp.net网络表单的形式完成) 而且我想将用户上传的任何视频转换为mp4.为此,我将Nreco ffmpeg包装器用于asp.

I'm making a Video sharing application(the likes of youtube) for my bachelor degree(the project is done in asp.net web forms) And i want to convert any video the user uploads to mp4.For this i'm using the Nreco ffmpeg wrapper for asp.

我正在本地进行所有操作,并且该项目无法上线.

I'm doing all this locally and this project is not going live.

视频转换是在单独的线程中完成的.

The video conversion is done in a separate thread.

protected void Upload_Click(object sender, EventArgs e)
{
//File Uploads to Server
Thread t1 = new Thread(
unused => compressVideo(Video_Path, Final_Path,User_id)
);
t1.Start();
}

public static void compressVideo(string Video_Path, string Final_Path,string UID)
{
    var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
    ffMpeg2.ConvertProgress += (o, args) =>
        {
            //SignalR calls.Doing this to update the ui
        };

    ffMpeg.ConvertMedia(Video_Path, Final_Path, NReco.VideoConverter.Format.mp4);
}

我第一次这样做,一切都很好,不是一个问题. 迟到两周,在不修改此页面后,我再次尝试,应用程序引发此异常:

First time i did this it all worked fine,not a single problem. Two weeks late,after not modifying this page,i try it again and the application throws this exception:

类型为'System.ComponentModel.Win32Exception'的未处理的异常 发生在NReco.VideoConverter.dll

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in NReco.VideoConverter.dll

其他信息:指定的可执行文件无效 该OS平台的应用程序.

Additional information: The specified executable is not a valid application for this OS platform.

在线:

ffMpeg.ConvertMedia(Video_Path, Final_Path, NReco.VideoConverter.Format.mp4);

如果我调用ffMpeg.ConvertMedia(),则不会引发异常并且代码按预期运行.所以我猜想它与线程有关,但这还不是全部. 在弄乱了试图解决该问题的代码后,我没有恢复原状,然后恢复为原始代码.在最后一次尝试中,我再次尝试了(使用原始代码),然后应用程序给出了构建错误.

If i call the ffMpeg.ConvertMedia(),the exception is not thrown and the code works as expected.So im guessing it has something to do with threads.But that's not all. After messing around with the code trying to solve this and not succeeding i revert back to the original code.In a last attempt i try it again(with the original code) and the application gave the build error.

试图访问已卸载的应用程序域.

attempted to access an unloaded appdomain.

我对代码所做的任何修改都会被忽略,并且在编译时总是会出现该错误. 休息了五分钟以使自己平静下来之后,我再次尝试了一下.它神奇地修复了自己的问题.构建错误消失了,甚至转换仍在进行.

Any modification i did to the code was ignored and i was always getting that error when compiling. After taking a five minutes break to calm down, i try it again.It magically fixed its self.The build error was gone and even the conversion was working.

但是梦想并没有持续太久,几分钟后转换线程开始再次引发相同的异常. 我无法复制相同的结果.

But the dream didn't last long.After a few minutes the conversion thread started throwing the same exception again. I was not able to replicate the same result.

我对asp.net Web表单和Web设计的经验和知识普遍较低,因此请尽可能简单地回答.

My experience and knowledge with asp.net web forms and web design in general are fairly low,so please keep the answers as simple as possible.

推荐答案

由于视频转换在同步调用下运行良好且稳定(仅来自Upload_Click处理程序的ConvertMedia),我可能建议以下原因:您已开始使用新线程进行转换t1.Start(),但是我没有看到等待线程结束的任何代码.结果,当前的请求处理已完成,但转换线程可能仍在运行并引发ConvertProgress事件(该事件可以访问已完成的请求的对象).根据情况(例如,asp.net应用程序重新启动/回收),转换可能会因试图访问已卸载的应用程序域"或其他错误而崩溃.

Since video conversion works fine and stable with synchronous call (just ConvertMedia from Upload_Click handler) I may suggest the following reason: you've started conversion in new thread with t1.Start() but I don't see any code that waits for thread end. As result current request handling is finished but conversion thread may still run and raise ConvertProgress event (which may access objects of request that was already finished). Depending on situation (for example, asp.net app restart/recycle) conversion may crush with "attempted to access an unloaded appdomain" or other errors.

如果要从asp.net应用程序在后台执行转换过程,可以使用

If you want to execute conversion process in background from asp.net application you may use HostingEnvironment.QueueBackgroundWorkItem (available only from .NET framework 4.5.2 or later) or organize your own background queue (for example create new "conversion task" in DB table and execute conversion by special worker implemented as Windows Service or Console app that periodically started with Windows Scheduler).

这篇关于C#指定的可执行文件不是此OS平台的有效应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆