编译错误 - 具有[Application]属性和[assembly:Application]属性的类型

Gus*_*san 4 c# android

我的应用程序类中有编译错误.这是我的代码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
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序类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();
    }
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

应用程序不能同时具有[Application]属性和[assembly:Application]属性的类型

感谢您提供有关如何解决此问题的任何建议.

Gus*_*san 7

解决方案:只需删除AssemblyInfo.cs中的行

(#if DEBUG ... #endif)
Run Code Online (Sandbox Code Playgroud)

并更换线

[Application]
Run Code Online (Sandbox Code Playgroud)

(在你的班上)有以下一个:

#if DEBUG
    [Application(Debuggable = true)]
#else
    [Application(Debuggable=false)]
#endif
Run Code Online (Sandbox Code Playgroud)