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

时间:2016-02-16 10:04:17

标签: 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

这是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();
    }

我收到此错误消息:

  

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

感谢您就如何解决此问题提出任何建议。

3 个答案:

答案 0 :(得分:7)

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

(#if DEBUG ... #endif)

并替换

[Application]

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

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

答案 1 :(得分:2)

当我删除下面的行并编译它时,我也遇到过它。

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

其他方式,你可以试试

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

答案 2 :(得分:0)

从AssemblyInfo.cs中删除以下代码

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

并将它们移到MyApplication类中

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

    }