Xamarin.Behaviors with Xamarin.Forms iOS

2019-07-11 02:20发布

问题:

Yesterday, I stuck in a bug relative to Xamarin.Behaviors and Xamarin.Forms. The detail is a Exception was thrown after i add these code line in my xaml page:

 <b:Interaction.Behaviors>
        <b:BehaviorCollection>
        <b:EventToCommand EventName="Clicked" Command="{Binding MyCommand}" />
        </b:BehaviorCollection>
 </b:Interaction.Behaviors>  

Although, I've added this line to xaml namespace

xmlns:b="clr-namespace:Xamarin.Behaviors;assembly=Xamarin.Behaviors"

Application got crash with exception: "Could not load file or assembly 'Xamarin.Behaviors' or one of its dependencies. The system cannot find the file specified."

Specially, It's only happened on iOS, android and wp still work well. So, I guess this could be xamarin bug or xamarin studio bug ...

P/S: I checked that Xamarin.Behaviors existed in package folder in my project, and App still not found where that assembly is

回答1:

To help somebody who also engage this bug. I will post my answer to show my solution for this. Nuget has problem with this lib and we can't use it anymore. I have to forget the Nuget and copy full of class in this library to my project. So, It look like your code which you wrote, not the library. Of course, we have to update this manually instead of use Nuget as before. Maybe, this solution is just temporary. Someone would find better one and I'll change my answer.



回答2:

I faced this issue in building my iOS project so after a lot R&D I added this line of code in my iOS AppDelegate.cs file

Xamarin.Behaviors.Infrastructure.Init ();

That's all I had to do, the above line of code helps the iOS files to forcefully link to some assemblies. Adding the above line resolved my crash.

Hope it helps