dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

MvvmCross: Getting error- Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type #2618

Closed parmendrahsc closed 5 months ago

parmendrahsc commented 5 years ago

Steps to Reproduce

  1. Create a application with mvvmcross
  2. create a android library project and put some vm and view on library project
  3. Getting error message on fragment line: [MvxFragmentPresentation(typeof(HomeActivityViewModel), Resource.Id.content_home, true)]
  4. Unable to get "content_home" and showing error message.
  5. when I go to defination of 'content_home' it shwoing property type is 'Static' public static int content_home = 2130837507; but Its need const type.
  6. How to use static value on this or can I can static to const.

    Expected Behavior

    It should run without error.

    Actual Behavior

    Severity Code Description Project File Line Suppression State Error CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type Ab.MyScan.Core.Droid C:\Users\e01699\Desktop\Framework\Ab.MyScan\Ab.MyScan\Ab.MyScan.Core.Droid\Views\Home\HomeFragment.cs 15 Active

Version Information

Microsoft Visual Studio Professional 2017 Version 15.9.4 VisualStudio.15.Release/15.9.4+28307.222 Microsoft .NET Framework Version 4.7.03056 Xamarin 4.12.3.77 (d15-9@e3f40b477) Xamarin Designer 4.16.13 (45a16efd4) Xamarin Templates 1.1.128 (6f5ebb2) Xamarin.Android SDK 9.1.4.2 (HEAD/8255f42fc) Xamarin.iOS and Xamarin.Mac SDK 12.2.1.12 (65ec520)

parmendrahsc commented 5 years ago

Any Update ??

parmendrahsc commented 5 years ago

I want MvvmCross with two core libraries

dellis1972 commented 5 years ago

The Resource.designer.cs file contains the id's for all the compiled resources to be used on android. For application projects these will be public const int however to library projects we need to use public static int.

This is because when you ship a library project and id that is used for the final application can and does change. As a result we need to update the library values at runtime. If you look at an application Resource.designer.cs you will see code like this

public static void UpdateIdValues()
        {
            global::Xamarin.Forms.Platform.Android.Resource.Attribute.actionBarSize = global::LinkTest.Droid.Resource.Attribute.actionBarSize;
        }

The code above is making sure that the Xamarin.Forms android platform is using the same idea for the actionBarSize as the one that was finally generated for the app. There isn't really a way around this since library projects can be shipped in binary form (via Nuget etc).

parmendrahsc commented 5 years ago

@dellis1972 for resolving this issue I have create Two Android project and one core library but now I get white blank screen. Attached Sample: https://drive.google.com/file/d/1H0zD9_0z-MNRv5taNo3k2MyNBHBImHag/view?usp=drive_web

EmilAlipiev commented 3 years ago

@dellis1972 so what you are saying it that it is not possible to use in an Andorid Library project? Is it a valid thing even today?

dellis1972 commented 3 years ago

@EmilAlipiev because of the way the android resource system works we cannot make library projects use const so they will always need to be static.