我试图从我的硬盘播放视频avi文件,但收到FileLoadException错误为什么?

时间:2013-04-12 11:13:47

标签: c#

这是我在Form1中的代码:

private void play()
        {
            pictureBox1.Load(vp.PlayVideoFile(@"D:\testdata\new.avi"));
        }

vp是我的VideoPlayer类的变量:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScreenVideoRecorder
{
    class VideoPlayer
    {
        public VideoPlayer()
        {
        }

        public string PlayVideoFile(string fileName)
        {
            //create the video
            Microsoft.DirectX.AudioVideoPlayback.Video video = new Microsoft.DirectX.AudioVideoPlayback.Video(fileName);
            //Play the video (put this in a buttons click event)
            video.Play();
            //Pause the video (put this in a buttons click event)
            video.Pause();
            //Stop the video (put this in a buttons click event)
            video.Stop();

            return fileName;
        }
    }
}

为什么我得到这个例外?

混合模式程序集是针对运行时的版本“v1.1.4322”构建的,如果没有其他配置信息,则无法在4.0运行时加载

需要哪些其他配置信息?怎么做?

System.IO.FileLoadException was unhandled
  HResult=-2146232799
  Message=Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
  Source=ScreenVideoRecorder
  StackTrace:
       at ScreenVideoRecorder.VideoPlayer.PlayVideoFile(String fileName)
       at ScreenVideoRecorder.Form1.play() in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\Form1.cs:line 107
       at ScreenVideoRecorder.Form1.timer1_Tick(Object sender, EventArgs e) in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\Form1.cs:line 58
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ScreenVideoRecorder.Program.Main() in d:\C-Sharp\ScreenVideoRecorder\ScreenVideoRecorder\ScreenVideoRecorder\Program.cs:line 19
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

编辑:

现在我在我的VideoPlayer类中获得了一个异常:

Microsoft.DirectX.AudioVideoPlayback.Video video = new Microsoft.DirectX.AudioVideoPlayback.Video(fileName);

例外情况是:检测到加载程序锁定:

DLL 'C:\WINDOWS\assembly\GAC\Microsoft.DirectX\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

检测到LoaderLock 消息:DLL'C:\ WINDOWS \ assembly \ GAC \ Microsoft.DirectX \ 1.0.2902.0__31bf3856ad364e35 \ Microsoft.DirectX.dll'正在尝试OS Loader锁内的托管执行。不要尝试在DllMain或图像初始化函数中运行托管代码,因为这样做会导致应用程序挂起。

1 个答案:

答案 0 :(得分:0)

使用以下内容将app.config文件添加到项目中:

 <?xml version="1.0"?>
 <configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v1.0"/>
    <supportedRuntime version="v4.0"/>
  </startup>
 </configuration>