I am attempting to build my first Xamarin android application.
I am using Visual Studio 2015 Community
I am new to Xamarin so apologies for any errors.
I created a simple project and then added a new project of type "Class Library (Android)"
I added simple async function and everything worked perfectly.
I then added my API which has a swagger definition using the Add > REST API Client
It downloaded my API and built the client for me - all looking great!
I'm getting really excited at this point.
But, the project will no longer build reporting an error of:
Severity Code Description Project File Line Suppression State
Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Microsoft.Threading.Tasks.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute() App5
I have hunted high and low on the internet looking for a solution but just cannot seem to fix the problem.
My initial "Hello World" function was working perfectly using async/await.
I don't understand what adding this new API Client has done and is using differently.
Can anyone shed any light on how to solve this please?
I believe you will need to add the REST Api to a PCL project, not an Android App project or Android Library project. See:
https://blogs.msdn.microsoft.com/visualstudio/2015/03/24/introducing-the-azure-api-apps-tools-for-visual-studio-2013/
The generated client code is also supported in Portable Class Library projects, so you can use them from any platform supporting PCL, like Windows Phone 8.1 and Universal apps, as well as apps written targeting Android and iOS with Xamarin.
Related
I have just started a MAUI app project and for the Windows platform target, under Dependencies/net6.0-windows10.0.19041.0/Assemblies, I have added two DLLs. One of them is a c# managed assembly and it uses Interop services(DllImport) to import the other c++ native assembly. It seems like VS is having trouble finding that c++ native dll(The reference is invalid or unsupported), the native dll has a yellow triangle with an exclamation mark in it but the c# dll doesn't have it. Also when I try to run the MAUI app and call into the c# assembly, VS would complain by throwing a DLLNotFoundException for the native DLL.
What am I missing here?
I ran into the same problem. I do not have a solution, but maybe you can verify that you have the same issue:
If you provide a full absolute path for the DllImport() (exact location of the dll you would like to import), it finds it and can use it gracefuly.
Reason for this is because deployed MAUI application for windows Directory.GetCurrentDirectory() method return c:\windows\system32.
I'm a longtime ASP.NET developer but new to Xamarin. I have a pretty simple NETStandard Xamarin project for Android built on Core 2.0 inside Visual Studio 2017. I've just begun building my app. In the common project I am using Microsoft.Data.Sqlite to work with a local database. That's the only library I'm pulling in besides Xamarin.Forms and NETStandard.
EDIT: I should note that this application used to compile just fine until I upgraded from Android API 26 to 27. I haven't changed any code. The problem isn't my code but either the project configuration or NuGet.
Here is the compile-time error that is not associated with any particular file:
Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Data.Sqlite, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Microsoft.Data.Sqlite.dll'
at Java.Interop.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)
I do not know why the Android app needs Sqlite, as the database stuff is being handled by the common project. This seems like a red herring but I can't make this error go away.
Here is NuGet for MyApp (common project):
Here is NuGet for MyApp.Android:
My first instinct is this long list isn't right, but all I did was Install-Package Xamarin.Forms and all these other things came with it. Prior to installing Xamarin.Forms, I removed all NuGet packages. I've been fighting NuGet for a while so the "default" list isn't the same anymore. I've had Crosslight in here at one point, among other things, possibly Sqlite. When I create a brand-new Xamarin Forms app, there are only six packages: Xamrin.Forms (v3.1.0), Xamarin.Android.Support.v4 (v27.0.2), ...v7.AppCompat (v27.0.2), ...v7.CardView (v27.0.2), and ...v7.MediaRouter (v27.0.2), though they are not the latest versions.
I've exhausted Google. The closest I could find to resolving this is this GitHub issue for Mono, but the specific library is System.Drawing.Common, not Microsoft.Data.Sqlite. As that thread stands, it's a bug with Mono. If so, what is the workaround?
Should I be concerned that MyApp.Android is mixing Support.v4 and Support.v7?
If it's a clue, MyApp has gone through a lot of massaging and playing around with NuGet to get various things to work. I've installed many libraries and removed them later. I've edited the .sln and .csproj files, I've deleted the Packages, obj, and bin folders multiple times. (Sqlite is not referenced in the .csproj file.)
I've tried copying my code from MyApp to a fresh Xamarin Forms MyApp2 but that has different issues (not finding the Sqlite database and crashing when displaying a toast notification, despite having identical code). MyApp didn't have either of these issues last week when everything was running and before I tried upgrading the API from 26 to 27.
And yes, I've Cleaned and Rebuilt my project innumerable times, as well as cleared the NuGet cache.
I am trying to use the (latest) Android API 27. I believe I created MyApp under API 26 but I'm not certain.
All I want to do is create a Xamarin Forms app for Android API 27 that uses Microsoft.Data.Sqlite! Why is this so hard? I've spent over 90% of my time on this project fighting code I didn't write!
Xamarin Forms/Visual Studio can easily get confused. Sometimes certain errors may go away just be restarting VS. I generally will close VS, nuke all obj + bin directores, and nuke the .vs directory. That will clean a lot of the cached cruff. Always close + reopen VS after change the major XF versions. (2.0<->2.5, 2.5<->3.0, 3.0<->3.1, etc.)
Beyond that, due to the large dependency tree of nuget packages, both explicitly referenced, and implicitly, it's possible to get into situation where various nuget packages won't be compatible.
Mono.Data.Sqlite is a strange case because there is some redundancy between the mono assemblies and the .net assemblies, and you have to specifically add that assembly in. See: https://forums.xamarin.com/discussion/99947/how-to-reference-mono-data-sqlite You may have to explicitly go and find that assembly and add it to your project. bleh.
Generally I don't use that for sqlite, and prefer https://github.com/praeclarum/sqlite-net and https://github.com/bordoley/SQLitePCL.pretty. I realize that other nuget packages may depend on Mono.Data.Sqlite
Under Visual Studio 2015, I have integrated Android C++ code into Xamarin and it works as expected. Now, I am trying to do the same for iOS and am running into some basic issues.
I am assuming the integration mechanism is the same for iOS as that of Android in the sense that a shared library (probably .so) is created that one can load using DllImport in C# code.
When I try to add a new C++ project for iOS to my solution, the only option that seems to make sense is Visual C++-->Cross Platform-->iOS-->Shared Library. I added this project type as MyTestShared. This actually ends up creating three projects - MyTestShared.Shared, MyTestShared.iOS, and MyTestShared.Android. Project MyTestShared.iOS already has an external method defined as char* iOSInfo(). However, when I try to add project MyTestShared.iOS as a reference to my MyMainApp.iOS project, I see an error "A reference to MyTestShared.iOS could not be added. An assembly must have a dll or exe extension."
Questions:
For Android C++, it generates exactly one project. Why does it create three projects for iOS C++?
How do I add a reference to MyTestShared.iOS? What is it that I am missing?
I see there is an option to create a static C++ library for iOS. Can I reference it somehow in my C# code?
Regards.
I had a Xamarin project that was working fine, but it was build some time ago. Now my requirement is to upgrade this project to a Xamarin.Forms project. So I installed the Form nuget package. And then I try build the project. What happen is all api levels setting gone from all the projects. So I increased the api level => min api lavel 19 and compile api level with latest.
After all this I'm getting this error:
Error 141 Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Mono.Android.Support.v4, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Mono.Android.Support.v4.dll'
at Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute()
I've tried to install the Xamarin.android.supprt.v4.dll from nuget but it made no difference.
I'm using Visual Studio 2013 and I've also updated my the Xamarin for Windows.
I can only guess, since I can't see your project file.
This looks like a PCL issue. Xamarin.Forms projects can be either "shared" or "PCL" flavor. The "shared" project has access to the same APIs as your iOS or Android projects. The "PCL" flavor only has access to a subset of the APIs and to make things more complicated - there sub-flavors of PCL.
If you're migrating an existing project to XF I'd say you may be better off with the "shared" flavor. If you're starting new or feel it wouldn't be too much to refactor - use PCL.
It looks like you have a PCL XF project and copied code that tries to use System.IO.File - one of several missing APIs - and you'll have to refactor this API use into a dependency service or use some IoC to access it.
In a nutshell you'll create an interface that offers the file functionality you need (save, load, delete...), implement that interface in your respective iOS/Android/Win project or even better - shared project - and use IoC to instantiate the interface in XF project. For examples see how MediaService from XLabs is used
Here is our question: How can recompile Google drive api sdk in dotnet?
=> We didn't find the source code.
=> In the binary package, there a single source file not shipped with a project and we don't know what to do with it.
Reason of the question:
In dotnet, we're unable to use the latest Google Drive api dll downloaded from Google: Google.Apis.Drive.v2
We are getting compilation errors like:
Warning 10
The primary reference "Google.Apis.Drive.v2" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Google.Apis.Drive.v2" or retarget your application to a framework version which contains "System.Runtime, Version=1.5.11.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Cause:
This is because we are in Visual Studio 2010 with dotnet framework 4.0.
Apparently Google.Apis.Drive.v2 is compiled with dependencies to framework 4.5.
We cannot upgrade our project to Dotnet framework 4.5 because we have only Visual Studio 2010 and it would take months of testing upgrading to visual studio 2012.
Troubleshooting
We have tried to use Binding redirection in app.config files but it's not working with Class library projects that reference assemblies that need redirection (here Google.Apis.Drive.v2).
For information, binding redirection was working fine if we changed the project to console application but failed when we switched back to class library.
#Google support:
- Where do we download the source code of Google Drive api dll and how do we build it?
- Do you plan to ship a library for dotnet 4.0 because forcing 4.5 will block a lot of companies?
I finally found the source code for older versions (that compiled with .NET 3.5) at: http://code.google.com/p/google-api-dotnet-client/source/browse/Services/?repo=samples&name=1.3.0-beta (Google Drive in particular - it doesn't seem to exist in the main set).
I'm having trouble interacting with the source repository with Mercurial, but I was able to directly download the CS file and compile it in my own project. I'll edit if I learn more.
You can checkout the code from https://code.google.com/p/google-api-dotnet-client/source/browse/