I am trying to rewrite a project into a Portable Class Library. But the problem is that it is using Async CTP, and I can't compile it as a library for WP and Windows Store App. If I don't include reference AsyncCtpLibrary.dll, compiler says that
The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)
If i include it, compiler still says the same errors and adds a warning:
The primary reference "AsyncCtpLibrary" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "AsyncCtpLibrary" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
How should I bear with that?
You can only currently use async/await in portable when targeting .NET 4.5 and Window Store apps. Outside of portable, you can use the Async Targeting Pack for .NET 4.0 and Silverlight 5.
In saying that though, we are working on an updated async targeting pack that adds support for async/await in portable when targeting Phone 7.5, Silverlight 5 and .NET 4.0, see: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2691068-support-async-in-portable-class-libraries. You will see this early October.
Update: We just release a beta of this: http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx.
Simple answer - AsyncCTP is not working in Visual Studio 2012 and cannot be used in any project. For .NET 4.0 and Silverlight 5 you can install Async Targeting Pack from NuGet that works in a similar fashion.
Async/await is in Portable Class Library supported only when targeting WinRT, .NET4.5 or Windows Phone 8 and even then the use is pretty limited. I can't go into more details here, because the Windows Phone 8 SDK is still under NDA.
For WP7.5 and VS2012 there is currently no way how to use async/await, but updated Async Targeting Pack for this platform should be available sometime.
Note also that AsyncCTP and Async Targeting Pack can't be used in Portable Class Libraries and it's unlikely it will change in the future. The result is in VS2010 you cannot use async/await in Portable Class Libraries.
You can try to use the AsyncBridge project instead of the AsyncCTP. I don't know if it will help. You'll have to compile in VS2012 to get this to work though (you can still target .NET4.0):
http://omermor.github.com/AsyncBridge/
http://www.simple-talk.com/blogs/2012/04/08/asyncbridge-async-on-net-4-0-using-vs11/
Related
Hi!
I'm getting a typeload exception, the assembly being loaded is targeting runtime version v2.0.50727, other assemblies targets v4.0.30319.
I've been reading about Assembly Redirection and I think it could solve this problem but I'm unsure how this would be applied in a UWP app as there is no app.config.
Any advice would be helpful!
System.TypeLoadException: 'Could not load type 'System.Net.Sockets.Socket' from assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.'
In UWP platform, it would be better to create a Universal Windows Class Library then add it as a reference into the UWP project. You can try to create a Universal Windows Class Library and add your code into it as the following image,
From Windows 10 Fall Creators Update(16299), UWP supports .Net Standard 2.0, you can also create a .NET Standard 2.0 Class Library in VS2017.
Last but not least, I think you should learn more about the relationship among .Net Framework, .Net standard and UWP, you can look into the following blogs to get a better understanding:
https://blogs.msdn.microsoft.com/dotnet/2016/09/26/introducing-net-standard/
https://msdn.microsoft.com/en-us/magazine/mt814993.aspx
I'm facing a compatibility issue for .NET project.
I have 2 projects:
1st project: Libary project. Target: windows Phone 7.0 OS version
project
2nd project: Console Appplication project. Refers/use the previous
library. Target: Framework .NET 3.5
When I try to run the 2nd project, I have an exception that happens when I call a function from the 1st library:
...Could not load file or assembly 'System, Version=2.0.5.0,
Culture=neutral, PublicKeyToken=7xxxxxxxx or one of its dependencies.
The system cannot find the file specified...
If I change the target for 2nd project to Framework .NET 4.0, it works well, no more crash.
Is my error really due to the different target versions ?
How can I make the 1st project to be compatible with framework 3.5 ?
As I said, 1st project was targeting framework 3.5 .NET and 2nd project was targeting Windows Phone 7.0.
Work around: change 2nd project to target framework 3.5 .NET. (in my case, I add to create a new project in my solution, which in fact was the same as the old one but targeting framework 3.5 .NET. Same sources used.)
Kindly rough but works.
I had excactly same issue. Installing Portable Class Library helped me.
https://msdn.microsoft.com/en-us/library/gg597391.aspx
There are links to downloads for different visual studio versions.
Hi I have the following issue, I am using xamarin on a Mac and created a cross-platform app solution using native single view app with portable class library.
In the portable class library i added one reference to newtonsoft.json v4.0.3 but when i rebuild my project i get errors like the following:
Reference to type 'System.ComponentModel.ITypedList' claims it is defined assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found.
What should i do?
Thank you very much in advance
Version 4.0.3 of Newtonsoft.Json is only available for .NET (2.0, 3.5, 4.0), Windows Phone 7 (I think) and Silverlight 4. This version does not support portable class libraries.
Use NuGet to download the latest Newtonsoft.Json version, it should provide a number of PCL alternatives, in particular a Profile 328 assembly that can target practically all modern platforms including Xamarin iOS and Android.
I have been using .NET 4.5 in Xamarin Studio with portable libraries and a Xamarin.Mac project. When the Xamarin.Mac project is set to .NET 4.5 and Microsoft Async is added via nuget, compile in Debug will succeed but Release/AppStore will fail with
error MM2002: Failed to resolve assembly: 'System.Threading.Tasks,
In this case, it is unnecessary to add the dlls (System.Threading.Tasks and System.Runtime) from BCL because they are already in .NET 4.5. If you switch to .NET 4.0 it will work, but I have a lot of code already in .NET 4.5 that cannot be reversed because of other dependencies.
Somehow, BCL is not recognizing the Xamarin.Mac .NET 4.5 project as .NET 4.5 and still requiring the dlls.
To replicate:
Create a new Xamarin.Mac project
Set it to .NET 4.5
Use nuget to fetch Microsoft Async (notice correctly it does not pull in System.Threading.Tasks or System.Runtime)
Switch to Release
Compile
How does BCL know if .NET 4.0 or .NET 4.5 is used? Maybe there is something I can declare in the csproj to make it recognize that System.Threading.Tasks (and System.Runtime) is already included. Or maybe some Environment variable? Or...?
Note. It is possible to reference the System.Threading.Tasks ans System.Runtime from the net40 nuget folder. And in the test project, this actually works - though it complains about "The predefined type System.Runtime.CompilerServices.AsyncStateMachineAttribute' is defined multiple times. Using definition frommscorlib.dll'" However, in my case I have a portable library which uses EventArgs and the build fails with error CS1684: Reference to type System.EventArgs' claims it is defined assemblySystem.Runtime - which of course it isn't.
I'm not sure how well Xamarin.Mac supports PCLs. You can try to add an app.config with binding redirects, similar to what is described here: http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy
Otherwise, I'd suggest filing a bug with Xamarin.
I have following configuration of my PC:
Windows 8
Visual Studio 2012
.NET Framework 4.5
My Project Configuration is:
WP 7.1
Silverlight 4.0
.NET Framework 4.0
CTP ASYNC (installed, using async and await keywords)
The project was written using VS2010 on Windows 7 machine for WP7.1. Now I have upgraded the PC to Windows 8 and have installed VS2012.
The project, however, complaining about 'async' modifier.
Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?
Any idea how to solve this problem?
thank you!
There is a newer version of the Async targeting package which supports Silverlight 4. Search for Microsoft.BCL.Async in NuGet, or run install-package Microsoft.Bcl.Async –prein the Package Manager Console. The package supports SL4, WP 7.1+ and Portable Libraries (yes!)
You will find a detailed description in the BCL team's blog Using async/await without .NET Framework 4.5
From the page you downloaded from:
This targeting pack is not required for projects targeting .NET Framework 4.5 or .NET for Windows Store apps. It is only required for projects targeting Silverlight 5 and .NET Framework 4.0. Earlier platform releases are not supported.
Upgarde to Silverlight 5?