Xamarin Forms对接Asterisk遇兼容问题,求适配替代库推荐
Hey there, let's work through this compatibility snag you hit with AsterNET.ARI in your Xamarin.Forms app. That NU1202 error is pretty straightforward: AsterNET.ARI 1.2.1 is built exclusively for .NET Framework 4.5, which doesn't play nice with Xamarin.iOS or Xamarin.Android's target frameworks. Here are your best options to get connected to your Asterisk server:
1. Use a Cross-Platform AsterNET Variant
- Look for community-maintained forks of AsterNET that target .NET Standard 2.0+—this is the framework Xamarin.Forms relies on for cross-platform compatibility. These forks often refactor the original code to remove .NET Framework-specific dependencies.
- Check NuGet for Asterisk libraries tagged with
.NET Standard; some popular alternatives have already done the heavy lifting for cross-platform support.
2. Directly Call Asterisk's REST APIs (ARI/AMI)
If you can't find a pre-built cross-platform library, roll your own integration using Xamarin's native HTTP/TCP tools:
- ARI (Asterisk REST Interface): Use
HttpClient(fully supported in Xamarin.Forms) to send GET/POST requests to your Asterisk server's ARI endpoint. You'll handle JSON serialization/deserialization for requests and responses, but this gives you full control without third-party dependencies. - AMI (Asterisk Manager Interface): If ARI isn't the right fit, AMI uses a TCP-based protocol. You can implement a simple TCP client in C# to send commands and listen for events—this works seamlessly on both iOS and Android.
3. Port AsterNET.ARI to .NET Standard
If you're set on using AsterNET.ARI specifically, you can migrate its source code to a .NET Standard project:
- Clone the AsterNET.ARI repository, create a new .NET Standard 2.0 class library, and move the original code into it.
- Update any .NET Framework-specific APIs (like outdated network utilities) to their .NET Standard equivalents. Once the port is complete, you can reference this custom library directly in your Xamarin.Forms projects.
Quick Tip
Don't forget to enable network permissions in your platform projects:
- For Android, add the
<uses-permission android:name="android.permission.INTERNET" />line to yourAndroidManifest.xml. - For iOS, ensure your
Info.plistallows network access (for iOS 10+, you'll need to add exceptions for HTTP requests or use HTTPS).
内容的提问来源于stack exchange,提问作者Greta

