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
Related
I have a Xamarin Forms app that requires me to dynamically load a single one of several possible assemblies at runtime (based on versioning). This should not be a problem as iOS can load assemblies using the mono interpreter. The problem I face is that the IPA and APK packages do not include the assemblies because they are not referenced directly in the app. I include them in the project references but they do not appear in the app package.
Is there a way to tell Xamarin to always include an assembly in the package regardless if it is being directly referenced in code?
==UPDATE==
I have a complete working POC with what I am trying to accomplish in terms of versioning in the application.
https://github.com/rlasker-b2w/XamVersioning
I specifically have to add references in the VersionSelector class otherwise the version projects do not get their assemblies added to the app package.
https://github.com/rlasker-b2w/XamVersioning/blob/main/VersionApp/VersionSelector.cs
I have a solution with:
A project that handles business logic through crud functions. At some point the project uses System.Runtime.Caching
Other webforms, MVC and RESTservice projects. (irrelevant to the topic)
A newly created Xamarins.Forms project targeting .netstandard2.0
My problem is that when I reference the business logic project in the Xamarin.forms project then the Xamarin.Android project errors that it can not resolve the reference System.Runtime.Caching referenced by the business logic project.
It suggests that I add a NuGet package or assembly reference for System.Runtime.Caching, or remove the reference to the business logic project.
I have tried installing the package for both the Xamarin.Forms project and the related Xamarin.Android project. But it does nothing.
I am in a bit of halt here since I am unable to figure what the problem is and better yet how to sovle it.
System.Runtime.Caching doesnt seem to be part of .Net standard hence you can not add it .Check the nuget log when you try to add it.
You might be calling web project/API project code directly from xamarin forms, dont do that. You need to isolate the two.
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
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.
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/