制作PCL Xamarin(MonoDroid / MonoTouch)兼容出现问题

4
我们已经创建了一个相当强大的PCL,希望能通过Xamarin在一些Droid/Touch应用中使用。
截至今天,我已安装了最新版的Xamarin,并将我们的PCL设置为使用Profile 158
然后,我进入我们的项目并更新了目标程序集:
.NET Framework 4.5 Windows Phone 8 .NET for Windows Store apps Xamarin.Android Xamarin.iOS
这样做之后,我遇到了许多编译错误。 这里有一张完整的图片。
我需要用Xamarin提供的System dll替换原先的dll吗?还是说我需要采取其他措施才能使这些东西正常工作?
注意:如果我上面表达不清楚,添加 Xamarin 目标之前,PCL 没有任何问题。
如所请求,这是构建输出。
1>------ Build started: Project: MyApplication.AppCore, Configuration: Debug Any CPU ------
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(25,29,25,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(25,43,25,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(53,29,53,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(53,43,53,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(55,38,55,71): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(55,52,55,67): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(85,29,85,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(85,43,85,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(102,29,102,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(102,43,102,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(120,29,120,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(120,43,120,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(144,29,144,61): error CS1502: The best overloaded method match for 'MyApplication.AppCore.Data.DbProviderExtensions.GetTableName(System.Reflection.MemberInfo)' has some invalid arguments
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(144,43,144,57): error CS1503: Argument 1: cannot convert from 'System.Type' to 'System.Reflection.MemberInfo'
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(171,41,171,54): error CS1061: 'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Data\DbProviderExtensions.cs(239,25,239,38): error CS1061: 'System.Type' does not contain a definition for 'GetInterfaces' and no extension method 'GetInterfaces' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\AutoMapper.cs(18,54,18,67): error CS1061: 'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\AutoMapper.cs(47,54,47,67): error CS1061: 'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\AutoMapper.cs(78,50,78,63): error CS1061: 'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\AutoMapper.cs(100,50,100,63): error CS1061: 'System.Type' does not contain a definition for 'GetProperties' and no extension method 'GetProperties' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\MigrationRunner.cs(61,40,61,48): error CS1061: 'System.Type' does not contain a definition for 'Assembly' and no extension method 'Assembly' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Infrastructure\MigrationRunner.cs(62,77,62,93): error CS1061: 'System.Type' does not contain a definition for 'IsAssignableFrom' and no extension method 'IsAssignableFrom' accepting a first argument of type 'System.Type' could be found (are you missing a using directive or an assembly reference?)
1>P:\MyApplication.AppCore\MyApplication.AppCore\Repositories\RepositoryBase.cs(60,30,60,50): error CS0117: 'System.Reflection.Assembly' does not contain a definition for 'GetExecutingAssembly'
2>------ Build started: Project: MyApplication.AppCore.Tests, Configuration: Debug Any CPU ------
2>  P:\MyApplication.AppCore\MyApplication.AppCore.Tests\x86\sqlite3.dll
2>  1 File(s) copied
2>  P:\MyApplication.AppCore\MyApplication.AppCore.Tests\x64\sqlite3.dll
2>  1 File(s) copied
2>  MyApplication.AppCore.Tests -> P:\MyApplication.AppCore\MyApplication.AppCore.Tests\bin\Debug\MyApplication.AppCore.Tests.dll
========== Build: 1 succeeded, 1 failed, 4 up-to-date, 0 skipped ==========

不确定是否看到一些代码行会有所帮助,但是,这里是

    public static void Create<TModel> ( this IDbProvider dbProvider, TModel model ) where TModel : class, new()
    {

        var tableName = GetTableName( typeof( TModel ) ); // LINE 25

    }

foreach ( 
    var collection in model.GetType()
                           .GetProperties() // LINE 171
                           .Where(
                               property =>
                               property.GetCustomAttributes( typeof( ManyToManyAttribute ), true ).Any() ) )
{
        if ( !IsGenericList( collection.PropertyType ) )  // LINE 176
            throw new ArgumentException( "The property must be an ICollection<>" );
}

    private static bool IsGenericList ( Type type )
    {
        if ( type == null )
            throw new ArgumentNullException( "type" );

        return type.GetInterfaces() // LINE 239
                   .Where( i => i.IsGenericType )
                   .Any( i => i.GetGenericTypeDefinition() == typeof( ICollection<> ) );
    }

它是否强制你使用新的反射API? - atomaras
@atomaras 我不知道有一个新的反射 API。 - Chase Florell
请展示一些代码,例如在 DbProviderExtensions.cs 文件中的第25行、171行和239行左右。 - Anders Gustafsson
我添加了几行代码,但我不确定它们是否有帮助。就像我说的,在尝试将Xamarin目标添加到PCL之前,这一切都是正常工作的。 - Chase Florell
@AndersGustafsson 我发布了一些代码...不确定它是否有用。 - Chase Florell
78/111 的确表现更好。 - Dbl
1个回答

0

Profile158不仅支持您列出的其他目标,还支持Silverlight 5。在添加Xamarin支持之前,您定位的是哪个配置文件?

尝试的一件事是定向Profile78,这应该是您列出的平台集。

如果这样仍然无法解决问题,您可以将错误从构建输出中复制并更新您的答案吗?屏幕截图上的错误很难阅读,并且不清楚它们是否都来自同一个项目。


之前的配置文件是104。所有的错误都来自同一个项目,下面有一个链接指向完整大小的图像。 - Chase Florell
@ChaseFlorell 你可以尝试把它改回Profile104,看看是否仍然成功编译?另外,PCL不应该有任何显式引用.NET Framework程序集,比如System.DLL或mscorlib,所以如果你的项目中有任何这些内容,请尝试将其删除。 - Daniel Plaisted
我已经开始重构项目,以使用WinRT应用程序指定的反射。看起来有所进展...将发布结果。 - Chase Florell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接