我试图从我的硬盘播放视频avi文件,但得到fileloadeexception错误的原因

本文关键字:fileloadeexception 错误 文件 我的 硬盘 avi 视频 播放 | 更新日期: 2023-09-27 18:08:44

这是我在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);

异常是:Loader lock was detected:

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 '试图在操作系统加载器锁定内托管执行。不要尝试在DllMain或图像初始化函数中运行托管代码,因为这样做会导致应用程序挂起。

我试图从我的硬盘播放视频avi文件,但得到fileloadeexception错误的原因

在项目中添加一个app.config文件,内容如下:

 <?xml version="1.0"?>
 <configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v1.0"/>
    <supportedRuntime version="v4.0"/>
  </startup>
 </configuration>
相关文章:
  • 没有找到相关文章