async / await in .NET 4.5 PCL targeting Mono for Android? - xamarin.android

I'd like to make a Portable Class Library (PCL) version of a .NET 4.5 library capable of targeting Mono for Android. This library also makes heavy use of async / await.
I understand that the latest Xamarin Preview release includes support for async / await, and it seems that others have async / await working with PCL, but can the combination be made to work? If so, can someone provide the secret formula?

I've got it working using .NET Framework Profile78. 78 appears to be the combination of .NET 4.5, Windows Phone 8, and .NET for Windows Store apps.
The easiest way is to update your .csproj file replace the existing TargetFrameworkVersion and TargetFrameworkProfile tags with these:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>

Related

Can i edit a .NET 6 Console C# project in .NET 4.7.2?

I used to program in .NET 4.7.2 (and still do), but my High School uses .NET 6
Currently we have started using C# console in .NET 6
I don't want to update to .NET 6 because i would also have to change my Unity editor version to one that supports VS2022
Is it possible to open .NET 6 projects in .NET 4.7.2, or am i gonna have to update Unity and reinstall VS, while scouring every part of my C:// partition to clean up junk/leftovers? I am very tight on free space especially on C://
No, you can't (if you mean anything more then editing text, cause for this you can use even notepad). But depending on language features used potentially you can copy-paste code into a .NET Framework 4.7.2 project and compile it. Or not, cause at least some newer features are not supported by older framework version.
Also you don't need full blown VS upgrade. You can look into installing just the .NET 6 SDK and VS Code (which requires less space compared to VS 2022).
Though I hugely recommend to extend your disk.

using .NET Standard 2.1 with UWP

I made the big mistake of taking some NuGet library updates today. It forced me to either roll back a week's worth of work or upgrade to ASP .NET Core 3.0. I hate to use stuff that's not production, but I didn't want to untangle the libraries either, so I upgraded. Then it forces me to retarget .NET Standard 2.1 libraries. Which I did.
My problem now is with the client UWP code. When I try to compile, I get:
error : Project '..\ClassLibrary1\ClassLibrary1.csproj' targets 'netstandard2.1'. It cannot be referenced by a project that targets 'UAP, Version=v10.0.10586'.
This happens even with a virgin UWP and .NET Standard 2.1 library. Any clues on how to make Visual Studio 2019 client code work with the latest upgrade?
All Windows 10 SDKs currently don't support .NET Standard 2.1.
Windows 10 19H2 is using the same SDK number as 19H1, so it is unlikely that it will support .NET Standard 2.1. (But I certainly hope it does.)
Microsoft hasn't made an official announcement, but Windows 10 20H1 is getting a meaningful SDK update, so it is likely that it will support it. And once that's the case, UWP apps will require 20H1 to run (so that will become the minimum supported version).
One of the big issue with this situation is that Entity Framework Core 3.0 requires .NET Standard 2.1, so it can't be used in UWP apps for now (Update: This issue is resolved with Entity Framework Core 3.1 supporting .NET Standard 2.0).
By the way, as an experiment, I was able to fork Entity Framework Core 3.0 (for SQLite) and make it compile on .NET Standard 2.0. I basically had to manually copy a few new APIs from .NET Core 3.0 (like IAsyncXXX). And it worked, so it is an option for people who really need it. Note that, I did not try it with the SQL Server provider.
Update: The UWP team is planning to enable UWP apps to use .NET 5 and that's when UWP will support .NET Standard 2.1 (and more). This could happen in 20H2 or 21H1.
UWP does not support .Net standard 2.1 yet. It only support till .Net standard 2.0 and that too from windows 1709 onwards.
If you look at the link for 2.1 it states
Platform Support
An upcoming version Universal Windows Platform
so it may be 19H2
UPDATE
Microsoft is going to release a new framework called WinUI 3, this is going to support UWP as well as Win32 based application model. WinUI 3 would support .Net 5 for both the platforms. WinUI 3 preview is going to be available in mid May 2020, with final release in late 2020. WinUI 3 would be supported on windows 10 1803+.

aspnet core 1.0 full .net framework on Linux

I have a few simple questions:
a) can I use mono on linux and osx to load the full .net framework like I would on windows by adding net46 to my project.json?
b) can I use mono as an alias like net46?
c) can I use mono with aspnet core 1.0 rtm projects on linux?
I have been looking at the dotnet docs, specifically the standard library and the table and the table with the platform support confuses me with the arrows and star under mono.
thanks
can I use mono on linux and osx to load the full .net framework like I would on windows by adding net46 to my project.json?
In theory, yes, that's exactly what you do: specify some version of net inside frameworks in your project.json and dotnet run will then use mono to run your application.
In practice, basic Hello World application works, but I'm not sure how well will more complicated applications work.
If you want to run dotnet build on the same machine, you will also need reference assemblies. The version I tested (mono 4.2.1) only contained reference assemblies up to .Net 4.5.1, so net451 works, but net46 doesn't.
can I use mono as an alias like net46?
I don't think you can, at least not without forking .Net Core SDK.
I don't understand why would you want to do that, but I believe doing so would require modifying DefaultFrameworkMappings in NuGet.Client.
can I use mono with aspnet core 1.0 rtm projects on linux?
I wasn't able to make a basic ASP.NET Core application run under mono. I don't know what the problem is, or how hard would it be to fix it. EDIT: I managed to work around the issue I encountered.
Mono is other thing. Yeah they developed mono like .net framework but you cannot use .net 4.6 on mono.
Read the following article. Click here
Micrsoft developed .net core a new framework to run .net on windows, linux, mac osx etc.

Can I develop libraries (dll's) with Monodroid which are consumed by native Java apps?

I would like to develop a library (like a dll or jar) with Monodroid that can be called by Java applications on Android.
Is this possible?
If not, is there another possibility? (IPC...)
There is a solution for iOS, is there a similar solution for Android?
http://www.guidebee.biz/forum/viewthread.php?tid=172
Thank you!
A DLL compiled for Mono for Android will need the Mono runtime in order to run it, so it wouldn't be very useful for a standard Java app. Xamarin has some good documentation on the architecture available here. It is possible to go the other way around, though, and use Java libraries from within a Mono for Android application.

Translating a .NET DLL using Monodroid

I have written a networking library using C# and .NET. .NET/Mono developers can use the library to develop multiplayer applications.
I want to make the library available on the Android platform so that native Android developers can use the library. Is Monodroid (Mono for Android) capable of performing this translation and what is the best way to proceed?
Thanks.
If I'm understanding the question correctly, you are looking to build a DLL using Mono for Android that you give to Java developers to use? That's not currently possible since Mono for Android isn't simply translating from C# to Java. Mono for Android apps include the Mono runtime, and .NET code is run against that. It generates callable wrappers so that Mono and Dalvik (the Java virtual machine in Android) can talk to each other, but without the Mono runtime the DLL wouldn't be very useful.
If the developer is using Mono for Android to build the application, then they can use your DLL in the app.

Resources