0

This is my code in Form1:

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

vp is a variable of my VideoPlayer class:

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;
        }
    }
}

Why im getting this exception ?

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

What additional configuration information does it need ? And how to do it ?

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: 

EDit:

Now im getting an exception in my VideoPlayer class on the line:

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

The exception is: 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 was detected Message: 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.

Ben Kochavi
  • 293
  • 1
  • 4
  • 15

1 Answers1

0

Add an app.config file to your project with the following content:

 <?xml version="1.0"?>
 <configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v1.0"/>
    <supportedRuntime version="v4.0"/>
  </startup>
 </configuration>
laszlokiss88
  • 4,001
  • 3
  • 20
  • 26
  • laszlokiss88 i tried now when im running the program i see apopup window say i need to install .NET 1.0 when i click ok it's taking me in my browser to an searching engine webpage: http://search.microsoft.com/en-US/search.aspx?processName=ScreenVideoRecorder.vshost.exe&platform=0009&osver=6&isServer=0 – Ben Kochavi Apr 12 '13 at 11:21
  • I added this to the app.config : but now im getting an exception in another place im editing my question with the new exception. – Ben Kochavi Apr 12 '13 at 11:23
  • I have downloaded it. I tried to install the directx june 2010 but in the end of the installation it said failed. And the dll wasnt there so i downloaded it. And im using windows 8 64bit and vidusal studio 2012 pro and my project is on .net 4.0 – Ben Kochavi Apr 12 '13 at 11:28
  • Can you copy the url? Maybe there is a 4.0 version from this. – laszlokiss88 Apr 12 '13 at 11:30
  • Have you installed the DirectX Software DevKit? http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=10084 (Maybe you should reference the dll from this.) – laszlokiss88 Apr 12 '13 at 11:32
  • This is the link of where i downloaded the file. I clicked on the green bar Download Now. http://www.dllme.com/dll/files/microsoft_directx_audiovideoplaybac.html – Ben Kochavi Apr 12 '13 at 11:33
  • Maybe i will try to install again but as i mentioned before in my question or here in comments i tried to install the directx sdk it was installing and just in the end it says Failed. And in the installed directory i saw that many files are missing including this needed dll. But i will try to install it again. – Ben Kochavi Apr 12 '13 at 11:34