AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Exception has been thrown by the target of an invocation.

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Exception has been thrown by the target of an invocation.

Postby Axis3B » Wed Dec 19, 2018 3:55 pm

Hello, I have been trying to use this library in Unity with the following code:
Code: Select all
videoSource = new FileVideoSource(fileName);
// set NewFrame event handler
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
videoSource.VideoSourceError += new VideoSourceErrorEventHandler(videoSourceErrorEventHandler);
videoSource.PlayingFinished += new PlayingFinishedEventHandler(playingFinishedEventHandler);
// start the video source
videoSource.Start();


I am receiving a VideoSourceErrorEventHandler with the following description: Exception has been thrown by the target of an invocation. Which unfortunately does not help much to figure out what is wrong. The only thing I can get from it is that it is from AForge.Video.DirectShow.FileVideoSource:WorkerThread() in the callstack. The dll files are in the plugin folder. I have tried in 32 and 64 bits, scripting runtime .Net 3.5 and 4.6, Unity version 2017.2.3p4 or 2018.3.0, I have tried running the code directly in a Unity script or in a managed dll, all resulting in the same error. Since I am out of ideas at this point, here I am.
Axis3B
 
Posts: 4
Joined: Wed Dec 19, 2018 3:31 pm

Re: Exception has been thrown by the target of an invocation

Postby andrew.kirillov » Wed Dec 19, 2018 6:01 pm

Hello,

Comment all code in your video_NewFrame method and see if it changes anything. If does, then exception comes from your code. Also you can try using AsyncVideoSource. Not that you need any async processing, but it may help you identifying exceptions coming from user code (see above link for docs).
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3379
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Exception has been thrown by the target of an invocation

Postby Axis3B » Wed Dec 19, 2018 8:32 pm

The only thing I have in all 3 handler is a log. I tried using the AsyncVideoSource, but the input file is an mp4, I ended up getting the error Cannot cast from source type to destination type, not sure what to change there. When using FileVideoSource, I'm guessing "fileName" is the complete file path? I tried changing Unity Script Compatibility from .Net 4.6 to .Net 3.5 and now I'm getting "The requested feature is not implemented". I tried using AForge.Video.FFMPEG.VideoFileSource in a managed dll, but that simply made Unity crash.

*Edit note: With AsyncVideoSource, if I don't use my file but use for example this url: http://88.53.197.250/axis-cgi/mjpg/vide ... lution=320×240, the new frame event is never called, no errors tho.
Axis3B
 
Posts: 4
Joined: Wed Dec 19, 2018 3:31 pm

Re: Exception has been thrown by the target of an invocation

Postby andrew.kirillov » Thu Dec 20, 2018 8:02 am

Axis3B wrote:I tried using AForge.Video.FFMPEG.VideoFileSource in a managed dll, but that simply made Unity crash.

VideoFileSource is made with managed C++ and uses native code of FFmpeg. You may miss some C++ Redistributables on your system.

I would suggest making a quick test application using Win Forms. Otherwise it is not clear what are you fighting with - AForge or Unity.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3379
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Exception has been thrown by the target of an invocation

Postby Axis3B » Thu Dec 20, 2018 3:49 pm

In a windows form app, when using ffmpeg I get the error:
Code: Select all
System.IO.FileNotFoundException: 'Could not load file or assembly 'AForge.Video.FFMPEG.dll' or one of its dependencies. The specified module could not be found.'

The dll is in already in the same folder as the other dlls at the root of the executable.

AForge.Video.DirectShow.FileVideoSource is however working here, but again not in Unity when being used as a library (as mentioned earlier).
Axis3B
 
Posts: 4
Joined: Wed Dec 19, 2018 3:31 pm

Re: Exception has been thrown by the target of an invocation

Postby andrew.kirillov » Fri Dec 21, 2018 7:46 am

Axis3B wrote:The dll is in already in the same folder as the other dlls at the root of the executable.

What about DLLs of FFmpeg library? You uderstand that AForge.Video.FFMPEG.dll is just a wrapper around FFmpeg.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3379
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Exception has been thrown by the target of an invocation

Postby Axis3B » Fri Dec 21, 2018 3:24 pm

andrew.kirillov wrote:What about DLLs of FFmpeg library? You uderstand that AForge.Video.FFMPEG.dll is just a wrapper around FFmpeg.

Yes, they are there as well in the Plugins folder, I managed to make it work in windows form with ffmpeg, but Unity still cant seem to "find" the files.
Axis3B
 
Posts: 4
Joined: Wed Dec 19, 2018 3:31 pm

Re: Exception has been thrown by the target of an invocation

Postby andrew.kirillov » Sat Dec 22, 2018 7:32 am

Well, if it works with Win Forms, but not with Unity, then it does not look like AForge.NET issue. Not an expert with Unity, so you may need to research.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3379
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework