Xamarin.Mac 4.5 with BCL Async release compile fails to resolve System.Threading.Tasks

℡╲_俬逩灬. 提交于 2019-12-13 18:03:34

问题


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:

  1. Create a new Xamarin.Mac project
  2. Set it to .NET 4.5
  3. Use nuget to fetch Microsoft Async (notice correctly it does not pull in System.Threading.Tasks or System.Runtime)
  4. Switch to Release
  5. 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.


回答1:


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.



来源:https://stackoverflow.com/questions/22361526/xamarin-mac-4-5-with-bcl-async-release-compile-fails-to-resolve-system-threading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!