Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile error - having type with an [Application] attribute and an [assembly:Application] attribute

Tags:

c#

android

I have a compile error in my application class. Here is the code I have in AssemblyInfo.cs:

    [assembly: AssemblyTitle("myApp")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCompany("")]
    [assembly: AssemblyProduct("")]
    [assembly: AssemblyCopyright("CCS")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyCulture("")]

    // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
    // The form "{Major}.{Minor}.*" will automatically update the build and revision,
    // and "{Major}.{Minor}.{Build}.*" will update just the revision.

    [assembly: AssemblyVersion ("0.1.0")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

#if DEBUG
[assembly: Application(Debuggable = true)]
#else
[assembly: Application(Debuggable=false)]
#endif

And this is my application class in MainActivity.cs:

[Application]
public class MyApplication : Android.App.Application
{

    //public static string globaly = "CSS!";
    public static int AppNr;

    public MyApplication(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
    {

    }

    public override void OnCreate()
    {
        // If OnCreate is overridden, the overridden c'tor will also be called.
        base.OnCreate();
    }

I am getting this error message:

Application cannot have both a type with an [Application] attribute and an [assembly:Application] attribute

Thanks for any advice on how to solve this.

like image 271
Gusan Avatar asked Feb 16 '16 10:02

Gusan


3 Answers

SOLUTION: just remove the lines in the AssemblyInfo.cs

(#if DEBUG ... #endif)

and replace the line

[Application]

(in your class) with the following one :

#if DEBUG
    [Application(Debuggable = true)]
#else
    [Application(Debuggable=false)]
#endif
like image 141
Gusan Avatar answered Oct 10 '22 06:10

Gusan


I have also encountered it once, when I deleted below lines and compiled it.

#if DEBUG
[assembly: Application(Debuggable = true)]
#else
[assembly: Application(Debuggable=false)]
#endif

Other Way,You can try it

https://forums.xamarin.com/discussion/7670/error-while-preparing-an-application-for-release

like image 2
Chaos Fractal Avatar answered Oct 10 '22 08:10

Chaos Fractal


Remove below code from your AssemblyInfo.cs

#if DEBUG
[assembly: Application(Debuggable = true)]
#else
[assembly: Application(Debuggable=false)]
#endif

And move them to MyApplication class instead

#if DEBUG
    [Application(Debuggable = true, UsesCleartextTraffic = true)]
#else
    [Application(Debuggable = false, UsesCleartextTraffic = false)]
#endif
    public class MyApplication : Android.App.Application
    {

    }
like image 1
TPG Avatar answered Oct 10 '22 07:10

TPG