Open Closed

System.PlatformNotSupportedException when running Xamarin-Forms on iOS using ABP Module with Autofac #2752


User avatar
0
alin.andersen created

Hey,

we have problems when running a module inside Xamarin-Forms on iOS.

We have the following code:

var application = AbpApplicationFactory.Create<Module>(options =>  // this line throws the exception
{
    options.UseAutofac();
});

application.Initialize();

We receive the following exception:

System.PlatformNotSupportedException: Operation is not supported on this platform.
  at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed () [0x00019] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs:664
  at System.IO.FileSystemWatcher.set_EnableRaisingEvents (System.Boolean value) [0x0001d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs:163
  at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher () [0x00040] in <bc6401a219974725bf7a82de6ab30543>:0
  at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken (System.String filter) [0x00034] in <bc6401a219974725bf7a82de6ab30543>:0
  at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch (System.String filter) [0x00024] in <bc6401a219974725bf7a82de6ab30543>:0
  at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0 () [0x00016] in <3cfa5edff95b45d581cfb833a66bda1f>:0
  at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[TState]..ctor (System.Func`1[TResult] changeTokenProducer, System.Action`1[T] changeTokenConsumer, System.Action state) [0x0001b] in &lt;a17448b39538493dabfebe0c018d8c10&gt;:0
  at Microsoft.Extensions.Primitives.ChangeToken.OnChange (System.Func`1[TResult] changeTokenProducer, System.Action changeTokenConsumer) [0x0001c] in <a17448b39538493dabfebe0c018d8c10>:0
  at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor (Microsoft.Extensions.Configuration.FileConfigurationSource source) [0x00036] in <3cfa5edff95b45d581cfb833a66bda1f>:0
  at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider..ctor (Microsoft.Extensions.Configuration.Json.JsonConfigurationSource source) [0x00000] in <13320dc1bda7441691d3d3ee4b6465b7>:0
  at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build (Microsoft.Extensions.Configuration.IConfigurationBuilder builder) [0x00007] in <13320dc1bda7441691d3d3ee4b6465b7>:0
  at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build () [0x0001b] in <3b2c752b86514c138e527d40dea12e05>:0
  at Microsoft.Extensions.Configuration.ConfigurationHelper.BuildConfiguration (Microsoft.Extensions.Configuration.AbpConfigurationBuilderOptions options, System.Action`1[T] builderAction) [0x000ee] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Microsoft\Extensions\Configuration\ConfigurationHelper.cs:49
  at Volo.Abp.Internal.InternalServiceCollectionExtensions.AddCoreAbpServices (Microsoft.Extensions.DependencyInjection.IServiceCollection services, Volo.Abp.IAbpApplication abpApplication, Volo.Abp.AbpApplicationCreationOptions applicationCreationOptions) [0x0001c] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Volo\Abp\Internal\InternalServiceCollectionExtensions.cs:30
  at Volo.Abp.AbpApplicationBase..ctor (System.Type startupModuleType, Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action`1[T] optionsAction) [0x0005a] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationBase.cs:49
  at Volo.Abp.AbpApplicationWithInternalServiceProvider..ctor (System.Type startupModuleType, Microsoft.Extensions.DependencyInjection.IServiceCollection services, System.Action`1[T] optionsAction) [0x00000] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationWithInternalServiceProvider.cs:27
  at Volo.Abp.AbpApplicationWithInternalServiceProvider..ctor (System.Type startupModuleType, System.Action`1[T] optionsAction) [0x00000] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationWithInternalServiceProvider.cs:15
  at Volo.Abp.AbpApplicationFactory.Create (System.Type startupModuleType, System.Action`1[T] optionsAction) [0x00000] in D:\ci\Jenkins\workspace\abp-commercial-release\abp\framework\src\Volo.Abp.Core\Volo\Abp\AbpApplicationFactory.cs:76
  at Volo.Abp.AbpApplicationFactory.Create[TStartupModule] (System.Action`1[T] optionsAction) [0x00000] in <73e55470c3b14481b288376a3bdad510>:0
  at App.ApplicationCreator.Create () [0x00001] in /Users/admin/Git/App/App/AbpCommercial/ApplicationCreator.cs:9
...
/Users/admin/Git/App/App/Main.cs:9

We know that System.Reflection.Emit is not supported on iOS. How can we make this work? We need the Dynamic Proxy Feature of ABP to call app services remotely.

Thanks!


5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    From the stack, the error exists in FileProviders.Physical.PhysicalFilesWatche instead of abp and autofac.

    Abp just using the Configuration => PhysicalFilesWatcher

  • User Avatar
    0
    alin.andersen created

    So it seems PhysicalFilesWatcher is not supported on Xamarin-iOS (or at least in our version). We do not need it anyway, so how can we turn this feature off?

    We tried finding any resources on how to turn it off, but we did not find anything.

    We tried to find a way to turn it off on the AbpApplicationCreationOptions options. But couldn't find anything.

    Can you point us to a documentation page or sample project?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a new IConfiguration

    using (var application = AbpApplicationFactory.Create<AppModule>(options =>
    {
        options.UseAutofac(); //Autofac integration
        
        options.Services.ReplaceConfiguration(your_custom_IConfiguration);
    }))
    
    
  • User Avatar
    0
    alin.andersen created

    Thanks for the input!

    Even if we fixed the issue with the configuration, we still have the issue with the dynamic proxies.

    We also had the following weird issues when compiling the solution on the iMac:

    /Users/admin/Git/Conzepta/Conzepta.iOS/MTOUCH: Error MT2101: Can't resolve the reference 
    'System.Collections.Generic.ICollection`1&lt;System.Action`2&lt;System.Type,Autofac.Builder.IRegistrationBuilder`3&lt;System.Object,Autofac.Builder.ConcreteReflectionActivatorData,Autofac.Builder.SingleRegistrationStyle&gt;>> 
    Autofac.Features.Scanning.ScanningActivatorData::get_ConfigurationActions()', referenced from the method 
    'Autofac.Builder.IRegistrationBuilder`3<TLimit,Autofac.Features.Scanning.ScanningActivatorData,TRegistrationStyle> Autofac.Extras.DynamicProxy.RegistrationExtensions::EnableClassInterceptors(Autofac.Builder.IRegistrationBuilder`3&lt;TLimit,Autofac.Features.Scanning.ScanningActivatorData,TRegistrationStyle&gt;,Castle.DynamicProxy.ProxyGenerationOptions,System.Type[])' in 'Autofac, Version=6.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da'. (MT2101) (Conzepta.iOS)
    

    We managed to make it build later, but no idea how ...

    So something is not really working with those Dynamic Proxies on Xamarin iOS.

    DynamicProxy needs System.Reflection.Emit: "... any another .NET platform that supports .NET Standard 2.0+ and runtime type generation using System.Reflection.Emit ..." https://github.com/castleproject/Core/blob/master/docs/dynamicproxy-introduction.md

    System.Reflection.Emit not available for Xamarin.iOS: "The System.Reflection.Emit is not available. " https://docs.microsoft.com/en-us/xamarin/ios/internals/limitations#no-dynamic-code-generation

    All in all, it is not possible to use the dynamic proxies on iOS. We will probably create the HttpClient ourself or use libraries like Refit for communicating with the backend.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Many features cannot be used if the platform does not support EnableClassInterceptors.

    You can try to remove the AbpAutofacModule in your project.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11