I'm trying to create a simple Voip client application using the Linphone NuGet (LinphoneSDK.5.1.73.nupkg).
For that I created a solution with two C# projects (target framework: .net Framework 4.8, ; target platform: x86): one as a wrapper of Linphone (named as My.Voip) and the other for the application itself (named as My.Voip.Client).
In My.Voip, I added the Nuget LinphoneSDK 5.1.73, that I previously downloaded to my computer.
In this project, I created a class with a function that returns the version of Linphone, following the tutorial from Linphone.
using Linphone;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace My.Voip
{
public class Engine
{
public Core StoredCore { get; set; }
public string Version()
{
Factory factory = Factory.Instance;
string assetsPath = Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "share");
factory.TopResourcesDir = assetsPath;
factory.DataResourcesDir = assetsPath;
factory.SoundResourcesDir = Path.Combine(assetsPath, "sounds", "linphone");
factory.RingResourcesDir = Path.Combine(factory.SoundResourcesDir, "rings");
factory.ImageResourcesDir = Path.Combine(assetsPath, "images");
factory.MspluginsDir = ".";
Core core = factory.CreateCore("", "", IntPtr.Zero);
// You should store the Core to keep a reference to it at all times while your app is alive.
// A good solution for that is to either subclass the Application object or create a Service.
StoredCore = core;
return Core.Version;
}
}
}
In My.Voip.Client, I added a reference to the My.Voip project.
Now, in My.Voip.Client, I created a winform that, on load shows the version of Linphone.
private void Form1_Load(object sender, EventArgs e)
{
My.Voip.Engine x = new My.Voip.Engine();
MessageBox.Show(x.Version());
}
The problem that I'm facing is that i get an error when I invoke the Version method:
System.DllNotFoundException: 'Unable to load DLL 'linphone': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
The error is traced back to the file ~My.Voip\linphonecs\LinphoneWrapper.cs, line 33104:
static public Linphone.Factory Instance
{
get
{
IntPtr ptr = linphone_factory_get(); //<-Exception is thrown here
Linphone.Factory obj = fromNativePtr<Linphone.Factory>(ptr, true);
return obj;
}
}
The Instance is invoked in the class Engine->function Version->Factory factory = Factory.Instance;
I've tried to change the target platform as x64 and AnyCPU, reference the Nuget directly to the winforms application, but I get always the same error. I've, also, tried to use the Nuget directly from the Linphone repository, and the result is the same error, too.
What do I need to do to run this correctly?
The following describes the necessary steps to use NuGet package LinphoneSDK.Windows (v5.2.77) in a WinForms project.
Since only x86 files exist for WinForms, before adding the NuGet package one needs to switch the build configuration from
AnyCPUtox86.At the end of this post (under Additional Information), you'll find the troubleshooting process I used to make the determination that the project needs to target x86.
Try the following:
Create a new Windows Forms App (.NET Framework) (name: VoipTest; Framework: .NET Framework 4.8)
Use Configuration Manager to change the configuration to x86
In VS menu, click Build
Select Configuration Manager...
Select the drop-down under Active solution platform, select
<New...>Select the drop-down under Type or select the new platform, select
X86Click OK
Click Close
Add NuGet package source
In VS menu, click Tools
Select Options...
Expand NuGet Package Manager
Select General
Under Package Management, select PackageReference
Select Package Sources
Click
You'll now see:
For name, enter Linphone (if desired the name can be changed)
For Source, enter:
https://gitlab.linphone.org/api/v4/projects/411/packages/nuget/index.jsonClick Update
Click OK
Open Solution Explorer
Add NuGet package (name: )
In Solution Explorer, right-click <project name> (ex: VoipTest)
Select Manage NuGet Packages...
Change the Package source to Linphone
Select LinphoneSDK.Windows
Select version 5.2.77
Click Install
If a message box appears, click OK
Create a new class (name: Engine**)
Add Button to Form1 (name: btnRun)
Double-click the button to add Click event handler
Form1.cs
When you build the solution, you'll notice that the DLLs get copied to the output directory.
Additional Information:
NuGet packages are downloaded to
%UserProfile%\.nuget\packageswhich is where you'll findlinphonesdk.windows\5.2.77. When one builds the project, the appropriate.targetsfile (underlinphonesdk.windows\5.2.77\build\<version>) is read. If one opensLinphoneSDK.Windows.targetsfile using Notepad, one sees the following:For more information see MSBuild .targets files.
In order to figure out what values are being used, in Visual Studio, one can
Change the verbosity of the build process
Then clean and re-build the project.
In order to know the values that are being used, in the Output window, search for
Platform. When configuration has been set to x86 one seesPlatform = x86.Next search for
TargetPlatformIdentifier. For a WinForms app, one seesTargetPlatformIdentifier = Windows.Now search for
LinphoneSDK-Framework, andLinphoneSDK-LibrariesPath, andLinphoneSDK-Platform. When configuration is set to x86, One sees:And if the build configuration is set to x64:
The path
is the same as
If one opens Windows Explorer and goes to the path, one notices that this path doesn't exist.
Likewise for AnyCPU:
Since the package only contains DLL files for x86 for the type of project that we've created, one needs to compile for x86 or no DLLs will be copied to the output folder.