编译错误 - 具有具有 [应用程序] 属性和 [程序集:应用程序] 属性的类型

本文关键字:属性 应用程序 类型 程序集 编译 错误 | 更新日期: 2023-09-27 18:34:50

我的应用程序类中有一个编译错误。这是我在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();
    }

我收到此错误消息:

应用程序

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

感谢您对如何解决此问题的任何建议。

编译错误 - 具有具有 [应用程序] 属性和 [程序集:应用程序] 属性的类型

解决方案:只需删除程序集信息中的行.cs

(#if DEBUG ... #endif)

并更换生产线

[Application]

(在你的班级里(与以下一个:

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

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

#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

从汇编信息中删除以下代码.cs

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

并将它们移动到"我的应用程序"类

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