【问题标题】:Im trying to play a video avi file from my hard disk but getting FileLoadException error why?我试图从我的硬盘播放视频 avi 文件但收到 FileLoadException 错误,为什么?
【发布时间】:2013-04-12 11:13:46
【问题描述】:

这是我在 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 或图像初始化函数中运行托管代码,因为这样做会导致应用程序挂起。

【问题讨论】:

标签: c#


【解决方案1】:

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

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

【讨论】:

  • laszlokiss88 我现在尝试运行程序时看到弹出窗口说我需要安装 .NET 1.0 当我单击确定时,它会将我在浏览器中带到搜索引擎网页:search.microsoft.com/en-US/…跨度>
  • 我在 app.config 中添加了这个: 但现在我在另一个地方遇到了一个异常,我正在用新的异常编辑我的问题。
  • 我已经下载了。我试图在 2010 年 6 月安装 Directx,但在安装结束时它说失败。而且dll不在那里,所以我下载了它。我使用的是 windows 8 64bit 和 vidusal studio 2012 pro,我的项目在 .net 4.0
  • 可以复制网址吗?也许有一个4.0版本。
  • 您是否安装了 DirectX 软件开发工具包? microsoft.com/en-us/download/…(也许你应该从这里引用 dll。)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 2013-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多