.net Library - StarDust.CasparCG.net

Thanks! Just tested with the prerelease version.
It’s now OK with spaces on path.

Hey :slight_smile:

Is there any wrapper for the current frame position / video progress when channel is playing a video?

Thanks!

Hi,

Not for now, but can be add. To do this you can do with the OSC library.

I was using the OSC library for this purpose.
Was just wondering if there was another way.

Thanks

No, the only best solution that I found in the past it’s to do with the OSC message.

Hi rom1,

I tried to use your packages under Visual Basic.
Unfortunately I can’t manage to get the connection to the server stable. Sometimes the connection can be established and sometimes the server console gets the command but the application throws an error:

"System.IO.FileNotFoundException: “Die Datei oder Assembly “System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.”
It works best with Server 2.11_NRK but actually always fails with 2.2.0, 2.2.2 or 2.3.0.

Here’s what I did:

Imports System.IO
Imports System.Reflection
Imports StarDust.CasparCG.net.AmcpProtocol
Imports StarDust.CasparCG.net.Connection
Imports StarDust.CasparCG.net.Device
Imports StarDust.CasparCG.net.Models
Imports StarDust.CasparCG.net.Models.Media
Imports StarDust.CasparCG.net.Datas
Imports Unity
Imports Unity.Lifetime

   Private Shared _container As IUnityContainer
   Private Shared Caspar As ICasparDevice

Public Shared Sub ConfigureCaspar()
        _container = New UnityContainer()
        _container.RegisterInstance(Of IServerConnection)(New ServerConnection(New CasparCGConnectionSettings("CASPAR-SRV-01", 5250)))
        _container.RegisterType(GetType(IAMCPTcpParser), GetType(AmcpTCPParser))
        _container.RegisterSingleton(Of IDataParser, CasparCGDataParser)()
        _container.RegisterType(GetType(IAMCPProtocolParser), GetType(AMCPProtocolParser))
        _container.RegisterType(Of ICasparDevice, CasparDevice)(New ContainerControlledLifetimeManager())
    End Sub


Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    ConfigureCaspar()
    Caspar = _container.Resolve(Of ICasparDevice)()
    AddHandler Caspar.ConnectionStatusChanged, AddressOf CasparServer_ConnectionStatusChanged

End Sub

Private Sub btn_connect_Click(sender As Object, e As EventArgs) Handles btn_connect.Click

        If Not Caspar.IsConnected Then
            Try
                Caspar.Connect()

            Catch ex As Exception
                If Caspar.IsConnected Then Caspar.Disconnect()
                Console.WriteLine(ex)
            Finally
                ' do anything
            End Try
        Else
            Select Case MessageBox.Show("Bist Du sicher, dass Du trennen möchtest?", "Verbindung zum Server trennen ....", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
                Case Windows.Forms.DialogResult.Yes
                    Caspar.Disconnect()
            End Select
        End If
End Sub

Any ideas or suggestions would be helpful.

Thanks.

Ingo

This error has nothing to do with the connection itself. Something with your references are not working the way it should.

And by the way: A select case with only one case can be made an If then. :smile:

Hi didikunz,

Thanks for the answer.
The application is more or less in testing mode. So there might more “cases” follow when the basics are running smoothly :grinning:
However I think the problem has to do with the library. Because it’s depending on the server version. NRK-Version mostly works while any other version doesen’t.
Strange…

Ingo

That is weird. Can you debug into the library to see were the error occurs and why it does not when you run it with the NRK version?

I’m a bit busy at the moment but I try as soon as possible.

Ingo

No need to hurry, I just wanted to help.

Yes, I appreciate that :grinning:

Did you add the reference on the dll System.ComponentModel.Annotations.
What is your .net version setted on your project ?

Hi rom1,

Meanwhile I was getting a little deeper into the problem.
I could eliminiate the “System.IO.FileNotFoundException” error bei deinstalling yout complete StarDust package. I compiled the source with my system and linked the newly compiled dlls to my project.
The “System.IO.FileNotFoundException” is now gone and I can connect to both version 2.1 and version 2.3 server.
But strangely it doesn’t work properly. Connection to the server works fine. I get the event “ConnectionStatusChanged” fired. When I try to disconnet from the server the console says “… disconnected” but the “ConnectionStatusChanged” event seems not to be raised. I never get the event fired.
In some cases however I get another error message that seems to be the cause for the event not being fired.
It occurs in TCPClient.cs.

private void GetTcpDataReceived()
        {
            lock (_readLocker)
            {
                if (_tcpClient == null)
                    throw new NullReferenceException(nameof(_tcpClient));

                if (!_tcpClient?.Connected ?? false)
                    return;



                if (_tcpClient.Available == 0)
                {
                    Thread.Sleep(10);
                }
                else
                {
                    var byteList = new List<byte>();
                    while (_tcpClient.Available > 0 && _tcpClient.Connected)
                    {
                        var buffer = new byte[1];
                        _tcpClient.Client.Receive(buffer, 0, 1, SocketFlags.None);
                        byteList.AddRange(buffer);
                        if (buffer[0] == StringEncoder.GetBytes(ReceiveDelimiter).First())
                        {
                            var array = _queuedMsg.ToArray();
                            _queuedMsg.Clear();
                            OnDelimiterMessageReceived(_tcpClient, array);
                        }
                        else
                            _queuedMsg.AddRange(buffer);
                    }

                    if (byteList.Count <= 0)
                        return;

                    OnEndTransmissionReceived(_tcpClient, byteList.ToArray());
                }
            }
        }

in line 400
throw new NullReferenceException(nameof(_tcpClient));

Message:
System.NullReferenceException
HResult=0x80004003
Nachricht = _tcpClient
Quelle = StarDust.CasparCg.net.Connection
Stapelüberwachung:
bei SimpleTCP.SimpleTcpClient.GetTcpDataReceived() in C:\Users\david\Downloads\StartDust.CasparCG.net-master(2)\StartDust.CasparCG.net-master\src\StarDust.CasparCG.net.Connection\TcpClient\TcpClient.cs: Zeile400
bei SimpleTCP.SimpleTcpClient.b__64_0(Object o) in C:\Users\david\Downloads\StartDust.CasparCG.net-master(2)\StartDust.CasparCG.net-master\src\StarDust.CasparCG.net.Connection\TcpClient\TcpClient.cs: Zeile145
bei System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.TimerQueueTimer.CallCallback()
bei System.Threading.TimerQueueTimer.Fire()
bei System.Threading.TimerQueue.FireNextTimers()
bei System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)

When trying to connect again after this error occured I sometimes get the “channel info” when asking for “version” which is weird too.

I am using Visual Studio 2019 / VB .NetFRamework 4.7.2

Ingo

Thanks Ingo, just check and reproduce the bug. I fix it on the new version.The disconnection doesn’t dispose object in the right order.

Can you try to use the nuget package and add a assemblyBinding redirection to you config file like this. Replace the 4.2.1.0 version to your current version in your project.

Thanks for your update and sorry to keep you waiting.

Concerning the redirection:
I’m not sure how to do this.
Do I have to insert a line into app.config?
Do you want me to do this with the old package or the new one?

Regarding the new package:
I’m not able to update the package. Crosscutting seems to incompatible with the other packages:

Schweregrad	Code	Beschreibung	Projekt	Datei	Zeile	Unterdrückungszustand
Fehler		Abhängigkeiten können nicht aufgelöst werden. "StartDust.CasparCG.net.Crosscutting 2020.1.17.2' ist nicht mit 'StarDust.CasparCg.net.AmcpProtocol 2020.3.29.2 Einschränkung: StartDust.CasparCG.net.Crosscutting (>= 2020.3.29.2)', 'StarDust.CasparCg.net.Connection 2020.3.29.2 Einschränkung: StartDust.CasparCG.net.Crosscutting (>= 2020.3.29.2)', 'StarDust.CasparCg.net.Device 2020.3.29.2 Einschränkung: StartDust.CasparCG.net.Crosscutting (>= 2020.3.29.2)' kompatibel.

Thanks
Ingo

You’re right. I had a mistake on the crosscuting lib namespace and assembly name. I rename it and it is on nuget now on the next version.

Hi rom1,

Thanks for your efforts.
Unfortunately nothing has changed in my project.
When using the package I get the message below when trying to connect:

System.IO.FileNotFoundException
  HResult=0x80070002
  Nachricht = Die Datei oder Assembly "System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
  Quelle = <Die Ausnahmequelle kann nicht ausgewertet werden.>
  Stapelüberwachung:
<Die Ausnahmestapelüberwachung kann nicht ausgewertet werden.>

Program stops at
704E3668 mov ecx,dword ptr [ebp+0Ch]

When compiling the dll in my Visual Studio and use them in my project the following happens:

  1. Connect -> ConnectionStatusChanged-Event fires
  2. Disconnect -> ConnectionStatusChanged-Event doesn’t fire but server console says “disconnected” -> mostly follwed by exception:
System.NullReferenceException
  HResult=0x80004003
  Nachricht = Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
  Quelle = StarDust.CasparCg.net.Connection
  Stapelüberwachung:
   bei SimpleTCP.SimpleTcpClient.GetTcpDataReceived() in C:\Users\david\Downloads\200408_StartDust.CasparCG.net-master\StartDust.CasparCG.net-master\src\StarDust.CasparCG.net.Connection\TcpClient\TcpClient.cs: Zeile403
   bei SimpleTCP.SimpleTcpClient.<Connect>b__64_0(Object o) in C:\Users\david\Downloads\200408_StartDust.CasparCG.net-master\StartDust.CasparCG.net-master\src\StarDust.CasparCG.net.Connection\TcpClient\TcpClient.cs: Zeile145
   bei System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.TimerQueueTimer.CallCallback()
   bei System.Threading.TimerQueueTimer.Fire()
   bei System.Threading.TimerQueue.FireNextTimers()
   bei System.Threading.TimerQueue.AppDomainTimerCallback(Int32 id)

I’m not sure what’s going on here.

Ingo

I still don’t understand why you get that error. System.ComponentModel.Annotations has, according to this link, something, that has to do with ASP.NET. So it should not be referenced in any of these projects.

And by the way: I simply would ignore the exception on disconnection (use a Try Catch block with an empty catch) as it does not matter, when it still disconnects and you only need to shutdown the program. I would guess, that the “TimerQueueTimmer” still fires after the port has been closed and so it goes wrong.