Xam.Forms.VideoPlayer icon indicating copy to clipboard operation
Xam.Forms.VideoPlayer copied to clipboard

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

Open aperrone opened this issue 5 years ago • 10 comments

I've developed an application and I've and [assembly:Application] inside the AssemblyInfo.cs source file.

[assembly: Application(Label = "biker.click")]

When I compile the Android version of the project, the following error is showed:

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

I think the problem is caused by the [Application] attribute inside the source file Xam.Forms.VideoPlayer.Android/MainActivity.cs at line 15

namespace Xam.Forms.VideoPlayer.Android
{
 {
  [Application]
  public partial class MainActivity : Application, Application.IActivityLifecycleCallbacks

Dear @pro777s, can you remove it?

Thank you

aperrone avatar Dec 08 '19 21:12 aperrone

Hello, @aperrone, In order to remove this attribute, i will have to abandon the implementation of the interface IActivityLifecycleCallbacks.

pro777s avatar Dec 09 '19 15:12 pro777s

Please do - because it breaks all our projects that depend on this ability.

logikonline avatar May 11 '20 05:05 logikonline

Cant use this plugin due to this

chrisfoulds avatar Jun 05 '20 10:06 chrisfoulds

I found out that Xamarin Essentials now offers a MediaPlayer when you enable the extended functionality. There is no need for another library @chrisfoulds

logikonline avatar Jun 06 '20 21:06 logikonline

@logikonline sorry I have been on xamarin essentials GitHub and can't see this, do you have a link ?

chrisfoulds avatar Jun 07 '20 05:06 chrisfoulds

@chrisfoulds https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement

logikonline avatar Jun 07 '20 07:06 logikonline

thank you @logikonline , ah forms experimental instead of essentials, either way perfect thank you sir

chrisfoulds avatar Jun 07 '20 07:06 chrisfoulds

Here is what the user chedabob wrote to me on this issue:

I ran into this issue because in my Android AssemblyInfo.cs, I had an #ifdef block to turn debugging on and off.

Solution was to remove that block, and create an Application class where I could set that attribute.

My Application class ended up looking like this

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

Try it until you've tested it.

pro777s avatar Dec 09 '20 16:12 pro777s

That didn't work me for in the end. I've had to remove any reference to Application from my code, but will need to find a solution for setting Debuggable but it works for now.

chedabob avatar Dec 09 '20 16:12 chedabob

I solved this problem by adding the attribute debuggable to the AndroidManifest.xml:   <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.anyapp" android:debuggable="false" .../>

pro777s avatar Dec 09 '20 17:12 pro777s