Sharp.XMPP with Xamarin Forms - c#

I am using Xamarin forms to create a chat application and to achieve that i am using Sharp.XMPP library from Nuget but i ran into issues.
It was stated that it doesn't support in PCL at here
So i converted the project into shared .net standard library following this blog
After adding following code
using Sharp.Xmpp.Client;
async void OnLoginButtonClicked(object sender, EventArgs e)
{
var user = new User
{
Username = usernameEntry.Text,
Password = passwordEntry.Text
};
string hostname = "localhost";
string username = user.Username;
string password = user.Password;
using (var client = new XmppClient(hostname, username, password))
{
client.Connect();
messageLabel.Text = "Login Success";
client.SendMessage("axcl#localhost", "juyugygyg");
}
}
Error Recieved :
Severity Code Description Project File Line Suppression State
Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Sharp.Xmpp, Version=1.0.2.2, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Sharp.Xmpp.dll'
at Java.Int rop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) app.Android
Can anyone help me out to how to bind a .net library dll into the project so that it can be used in xamarin forms.
Another alternative is agsXMPP .NET SDK but am not sure much of it.
If i missed something. Sorry for that

First remove sharp nuget and clone this.
https://github.com/pgstath/Sharp.Xmpp .
Open the solution of sharp and build it.
You will get Sharp.Xmpp.dll under bin\debug.
Add reference of this .dll to your project.

Related

How can I migrate from In-App Billing Plugin 4.0.2 to 6.7.0? I get some errors when I try to use 6.7.0

https://github.com/jamesmontemagno/InAppBillingPlugin
I'm trying to migrate from In-App Billing Plugin 4.0.2 to 6.7.0 but I get the following errors in my Verify.cs:
using System.Threading.Tasks;
using Plugin.InAppBilling;
using AndroidProject;
using SharedCode;
[assembly: Xamarin.Forms.Dependency(typeof(Verify))]
namespace AndroidProject
{
public class Verify : IInAppBillingVerifyPurchase
{
const string key1 = #"...";
const string key2 = #"...";
const string key3 = #"...";
public string SignedDataverify = "Test", Signatureverify = "Test";
public Task<bool> VerifyPurchase(string signedData, string signature, string productId = null, string transactionId = null)
{
var key1Transform = InAppBillingImplementation.InAppBillingSecurity.TransformString(key1, 1);
var key2Transform = InAppBillingImplementation.InAppBillingSecurity.TransformString(key2, 2);
var key3Transform = InAppBillingImplementation.InAppBillingSecurity.TransformString(key3, 3);
SignedDataverify = signedData;
Signatureverify = signature;
return Task.FromResult(InAppBillingImplementation
.InAppBillingSecurity.VerifyPurchase(key1Transform + key2Transform + key3Transform, signedData, signature));
}
}
}
image
I use now Microsoft.Maui.Essentials instead of Xamarin.Essentials. I have removed the NuGet packages Xamarin.Essentials and Xamarin.Forms from my Android/iOS projects. But now I get this error:
Error CS0234: The type or namespace name 'Forms' does not exist in the namespace 'Xamarin' (are you missing an assembly reference?)
And the following error:
InAppBillingImplementation does not contain a definition for InAppBillingSecurity.
Is it still necessary to use the Xamarin.Forms NuGet package in my iOS and Android projects if I want to use In-App Billing Plugin 6.7.0 or can I use In-App Billing Plugin 6.7.0 with Microsoft.Maui.Essentials?
What is the problem with InAppBillingSecurity? Is it no more possible to use this code from version 4.0.2 to secure the purchases? Can I remove Verify.cs from my projects?
Is it still necessary to use the Xamarin.Forms NuGet package in my iOS and Android projects if I want to use In-App Billing Plugin 6.7.0 or can I use In-App Billing Plugin 6.7.0 with Microsoft.Maui.Essentials?
You used Dependency attribute. It belongs to Xamarin.Forms namespace. So it is necessary to use the Xamarin.Forms NuGet package. For more information, you can refer to Dependency Service by official. By the way, is your project Xamarin.Forms or MAUI?
What is the problem with InAppBillingSecurity? Is it no more possible to use this code from version 4.0.2 to secure the purchases? Can I remove Verify.cs from my projects?
I tested the code you provided, and also encountered this error: InAppBillingImplementation does not contain a definition for InAppBillingSecurity. But back to 4.0.2, it works well. You can refer to 'InAppBillingImplementation' does not contain a definition for 'HandleActivityResult'. Author gave
advice. I think you can continue to use 4.0.2. I also see your issue (I get some errors after migrating from 4.0.2 to 6.7.0) on GitHub, and you can follow up it to wait author's reply. In addition, you can check the README.md by author.

Class Not Registered Microsoft Speech Object library SpeechLib

I have set a reference to speechlib and trying to run the following code:
static void RunTraining()
{
SpSharedRecoContext RC = new SpSharedRecoContext();
string Title = "My App's Training";
ISpeechRecognizer spRecog = RC.Recognizer;
spRecog.DisplayUI(hWnd, Title,
SpeechLib.SpeechStringConstants.SpeechUserTraining, "");
}
However I am getting a class not registered 0x80040154
As it is a com object library I am compiling x86 and I have also run regsvr32 on the sapi.dll but to no avail.
Any help greatly appreciated, the code is in C#

Could not load file or assembly 'Autofac, Version=2.6.1.841 with webservice

I'm building an web service on sharepoint with IoC. Here is my main code:
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1), WebService(Namespace = "http://tempuri.org/")]
class WebService : System.Web.Services.WebService
{
private static IContainer Container { get; set; }
private DataTable Articles=new DataTable();
private string display;
[WebMethod(EnableSession = true, Description = "Web method for using search service")]
public string DisplayArticles()
{
var builder = new ContainerBuilder();
builder.RegisterType<WebServiceRepo>().As<IArticlesRepository>();
Container = builder.Build();
Search();
return display;
}
public void Search()
{
using (var scope = Container.BeginLifetimeScope())
{
var repo = scope.Resolve<IArticlesRepository>();
Articles.Load(repo.GetArticles(),LoadOption.OverwriteChanges);
display = repo.ReturnArticles(Articles);
}
}
}
The problem is an error I'm getting when trying to invoke method that uses Autofac:
System.IO.FileNotFoundException: Could not load file or assembly 'Autofac, Version=2.6.1.841, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified.
at SOAP_WebService.WebService.DisplayArticles()
It says about file not being found, but an Autofac.dll with version 2.6.1.841 exists in bin/debug folder. I'm using this version of autofac because working on sharepoint 2010, I can only choose .net framework v3.5 and it's one of the newest version that operates on this version of .net framework.
Answers provided in simmiliar questions did not help me.
Somehow i managed to work it out... If anyone will have a simmiliar problem:
The Autofac assembly I added to the references in my project, was somehow impossible to find by visual studio, despite the fact that file existed in my project (I'll be gratefull if someone will explain me why did it happen). The solution to it was adding this assembly to the GAC via Developer Command Prompt by this command:
gacutil /i <path to the assembly> /f

UWP - SQLite issues when compiling in native

I was developing my app using SQLite, on "Debug" mode, worked perfectly.
When I try to "Release" it (Compiling "Native"), the problem started, looks like UWP doesn't support Reflexion.
I'm currently using this packages:
SQLite.Core.UAP
SQLite.Net-PCL
For example, if I try to do this:
private void CreateDatabase()
{
var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite");
SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false);
SQLiteConn.CreateTable<StoredEvents>();
}
These are some of the error:
ILTransform_0027: Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found.
Error at SerializationAssemblyGenerator.Program.AddKnownContractsLists(McgCodeTypeDeclaration container, ContractTables tables)
Severity Code Description Project File Line Suppression State
Error at SerializationAssemblyGenerator.Program.GenerateDataContractSerializerHelperCode(IEnumerable`1 contracts, IEnumerable`1 jsonContracts, IEnumerable`1 wcfSerializers)
ILTransform_0000: MCG : warning MCG0006: Unresolved P/Invoke method '_TPM_Init!tpm.dll' in assembly 'TSS.UWP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because it is not available in UWP applications. Please either use an another API , or use [DllImport(ExactSpelling=true)
How should I refactor the code?
Should I use a different Library?
I had the same issue when i was updating my apps from Silverlight to UWP. I read an article somewhere ( Tried to find it but was unable to ) which says SQLlite for UWP is available for Windows 10 deployment.
The above is a VS Extension. You can get there from Tools ->> Extensions & Updates
Below is how my References look like.
Also I noticed that you are not closing your db connection. Always better to use it inside a using statement. your CreateTables() will look something like below.
private void CreateDatabase()
{
var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "StoredEvents.sqlite");
using (SQLiteConnection SQLiteConn = new SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), dbPath, false))
{
SQLiteConn.CreateTable<StoredEvents>();
}
}

ServiceStack client on a Xamarin.iOS project

I am trying to use the ServiceStack clients on a Xamarin iOS project and when debugging it I have the following exception:
“System.ArgumentException: PclExport.Instance needs to be
initialized”.
The code that produces the exception is the following:
try
{
string strReadParam = this.xmlParser.GetString("SyncUrl");
CommonStatic.SyncWSUrl = strReadParam;
var client = new JsonServiceClient(CommonStatic.SyncWSUrl);
client.Timeout = new TimeSpan(0, 0, 0, 5, 0);
var response = client.Get(new mSalesCheckConnectionRequest { DBSource = CommonStatic.DBSource, DBSourceInstance = CommonStatic.DBSourceInstance, DBName = CommonStatic.DBName, DBUsername = CommonStatic.DBUsername, DBPassword = CommonStatic.DBPassword });
return;
}
catch (System.Net.WebException wex)
{
}
I am using ServiceStack.Interfaces, ServiceStack.Client.Pcl and ServiceStack.Text.Pcl all having version 4.0.34. Additionally I referenced Newtonsoft.Json at version 6.0.7.
After some research I realized that the PCL provider for iOS is not registered automatically, so I added “IosPclExportClient.Configure();” before instantiating the new Json Service Client and a I referenced ServiceStack.Pcl.iOS.dll at version 4.0.0.0.
The result is the following error:
“Cannot include both 'monotouch.dll' and 'Xamarin.iOS.dll' in the same Xamarin.iOS project - 'Xamarin.iOS.dll' is referenced explicitly, while 'monotouch.dll' is referenced by 'ServiceStack.Pcl.iOS, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null'.”
Is there is any suggestion of resolving this problem?
Thank you in advance
You need to call IosPclExportClient.Configure(); when you application starts to initialise the PCL Export Client before use in iOS applications.
So in your Main method:
static void Main (string[] args)
{
// Configure ServiceStack Client
IosPclExportClient.Configure();
// Set AppDelegate
UIApplication.Main (args, null, "AppDelegate");
}
and a I referenced ServiceStack.Pcl.iOS.dll at version 4.0.0.0.
The PCL specific NuGet packages of ServiceStack are no longer maintained, as they have been merged into the main NuGet package using specific profile.
You should only be including the ServiceStack.Client package in your project. So remove all references to ServiceStack in your project, clean the build, and add just ServiceStack.Client.
If you reference ServiceStack.Client.Pcl was well as ServiceStack.Client you will get a conflict.

Categories

Resources