I'm attempting to use the OkHttp-Xamarin library in a Xamarin Android application. Whenever I try to create a new OkHttpNetworkHandler I get the exception below.
Line:
var handler = new OkHttpNetworkHandler();
Throws:
[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly /data/data/com.my.app/files/.__override__/OkHttp.dll
[MonoDroid] UNHANDLED EXCEPTION: System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
[MonoDroid] at ModernHttpClient.OkHttpNetworkHandler..ctor () <IL 0x00001, 0x00057>
I am using prebuilt binaries from ModernHttpClient version 0.9. My minimum Android version is set to 2.3 and target is set to 4.2. I'm using Xamarin Studio 4.0.13 and Mono 3.2.3.
So this looks like the first call to your binding code.
A couple things could be going on here:
Make sure you are using EmbeddedJar instead of InputJar as the build action for the jar file. Otherwise, you have to include the jar with your main Android application.
Make sure your main application has a reference to the binding DLL, it causes problems if only a dependent project has the reference.
If neither of those fix your issue, let me know, I think there is a working binding Paul Betts has for this library.
Not really an answer to why the Exception is being thrown but at the suggestion of Paul Betts I switched to the Alpha channel and things are working now.
Related
Just getting started with Blazor, trying to use Sqlite using Microsoft.Data.Sqlite library.
Created a data class which works fine in Windows Forms project where underneath the bin folder the net5.0-windows folder contains a runtimes folder containing e_sqlite3 dlls for various platforms.
Created a simple "Hello World" Blazor web app and added my data class and get following error:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.DllNotFoundException: e_sqlite3
The bin folder does not contain any runtimes folder or the e_sqlite3 dll.
Searching Google this seems to be a common error and is clearly about how the packages get deployed but I have not found a solution.
Ant pointers?
In .NET 5 you can't use SQLite with Blazor in web app/browser.
However, as of .NET 6, you can include native dependencies in Blazor WebAssembly. Inside dotnet conf 2021 they even show show that. It's working very nicely.
You can see this in action here: Steven Sanderson on Blazor WebAssemby # .NETConf21 (approx. 30 minutes watch time).
A code sample for the above is available on Steve Sanderson's GitHub repo.
I try to connect to a fiscal device with a C#.
I use this documentation to do so: http://integration.atol.ru/api-en/#connection-to-project
So basically I have a driver of the device installed on my PC (fprt10.dll) and there is a "wrapper" assembly that allows me to work with this driver from C# (Atol.Drivers10.Fptr.dll). I import this wrapper into my project as a reference.
I have the following constructor in my class:
public MyClass()
{
IFptr fiscalPrinter = new Fptr();
// Here comes several settings to configure connection
fiscalPrinter.applySingleSettings();
fiscalPrinter.open();
fiscalPrinter.beep();
fiscalPrinter.close();
}
To test the solution I use another application, that loads my Class Library as a dependency.
When I call a constructor of MyClass I get an exception:
System.IO.FileNotFoundException: Driver not installed
at Atol.Drivers10.Fptr.Fptr.loadDriver(String path)
at Atol.Drivers10.Fptr.Fptr..ctor()
at MySolution.MyClass.MyClass()
...
If I create instance of Fptr with a path to the driver
IFptr fiscalPrinter = new Fptr(#"C:\path\fptr10.dll")
I get the slightly different exception, but I believe the problem is the same:
System.IO.FileNotFoundException: Can`t load driver library "C:\path\fptr10.dll"
at Atol.Drivers10.Fptr.Fptr.raiseNotFoundError(String path, Exception reason)
at Atol.Drivers10.Fptr.Fptr.loadDriver(String path)
at Atol.Drivers10.Fptr.Fptr..ctor(String libraryPath)
at MySolution.MyClass.MyClass()
...
But when I create a Console Application and put in there exact same code (both versions with path and without), everything works: the device beeps, there are no exceptions.
What could be the reason for that behavior and how to fix this?
The issue may be one of the following
The test application is using 'target platform' different than the console application which works fine. The device driver folders expected for each platform could be different. e.g. Changing the targeted platform from 'any CPU' to 'x64' / 'x86' (depending on the type of OS where you are running it) will help
Try running the test application from admin command prompt. Permissions issue may reflect as 'file not found' (instead of 'file could not be loaded').
Use an assembly binding viewer tool to debug the issue further
Refer to Could not load file or assembly or one of its dependencies for more discussion and inputs on the assembly loading issues.
Thank you samiksc.
The issue was in the test app. The driver and OS that I use are both x64, but the test application is x86. With x86 driver everything works.
I am trying to build a Unity Project targeting Android platform from the cmd line. The C# script to build the project with the required options is titled PerformBuild.cs and is inside the project path. The class contains the method ConfigureBuildTestApp implemented.
$UNITY_PATH/Unity -quit -batchmmode -projectPath "$PROJECT_FINAL_PATH" -logFile -executeMethod PerformBuild.ConfigureBuildTestApp -buildTarget Android
The following error is observed in the build trace
executeMethod class 'PerformBuild' could not be found.
Argument was -executeMethod PerformBuild.ConfigureBuildTestApp
Any solution and/or reasoning for this problem? I followed the forum posts in the unity forum but none was helpful.
The script PerformBuild.cs
Compilation Errors were observed with the script above. Fixed the compilation errors and the revised script is shown below.
Revised PerformBuild.cs
The initial error for -executeMethod is still observed.
executeMethod class 'PerformBuild' could not be found.
Argument was -executeMethod
testIntegrationProject.PerformBuild.ConfigureBuildTestApp
(Filename:
/Users/builduser/buildslave/unity/build/Runtime/Utilities/Argv.cpp
Line: 295)
We had the "executeMethod class could not be found" error when a new plugin was used but was not present in the remote build server, causing all C# code to not compile, hence the error. Try manually building the project on the machine where you are building via command line and see if it succeeds.
Remove the namespace from class PerformBuild
I'm loading a solution at runtime using MSBuild like that:
private Solution LoadSolution(string solutionPath) {
var msw = MSBuildWorkspace.Create();
var solution = msw.OpenSolutionAsync(solutionPath).Result;
return solution;
}
This works when I tried it in a console application however it throws an AggregateException when I try to run it in a WPF application which references the console application in which the LoadSolution method is located.
I tried doing it with async/await but whenever I do that I never receive a result from the thread.
The error I receive states :
First exception :
One or more errors occurred.
Inner exception :
{"Object reference not set to an instance of an object."}
Framework version 4.5.2.
The resolution mentioned in GitHub Roslyn issue tracker, to install Microsoft.CodeAnalysis v1.0.0.0 worked for me. I tried to execute the code mentioned in the question on .NET 4.5.2 console application.
I'm very new to C#, MonoMac and Xamarin and am trying to play some generated audio with C# and Xamarin.Mac using this awesome example.
Unforunately the first line:
AudioSession.Initialize();
throws an EntryPointNotFoundException.
I've stumbled upon this forum post where someone is having a similar problem and suggests that it has to do with an incorrect binding.
Can I actually get this to work? If not, what can I use instead?
Thank you so much for your help.
My System
Xamarin.Mac: 1.2.43
Xamarin.Studio Version 4.0.3 (build 13)
Mono 2.10.12 (mono-2-10/c9b270d)
GTK 2.24.16
GTK# (2.12.0.0)
Package version: 210120000
Stack Trace
System.EntryPointNotFoundException: AudioSessionInitialize
at at (wrapper managed-to-native) MonoMac.AudioToolbox.AudioSession.AudioSessionInitialize (intptr,intptr,MonoMac.AudioToolbox.AudioSession/InterruptionListener,intptr) <IL 0x00011, 0x0007b>
at MonoMac.AudioToolbox.AudioSession.Initialize (MonoMac.CoreFoundation.CFRunLoop,string) [0x00013] in /Users/builder/data/lanes/xamcore-lion-bs1/0c83ca0e/source/xamcore/maccore/src/AudioToolbox/AudioSession.cs:225
I think that AudioSession is not used on OS X.
The sample code you are working from is likely for iOS.
If you check the documentation for AudioSession, you will see:
These functions apply only to iOS. They do not apply to Mac OS X.
Additionally, see this discussion. AudioSession is simply not available, which is why you get EntryPointNotFoundException when trying to call it...