0
votes

I've got a Xamarin.Forms app. at one time, I had this working, but alas, something has happened and now it no longer works. In my Android project, I have a dependency service as shown below. I am just trying to play a sound on the local system in the background. Now, out of the blue, I am getting an error on compile saying that 'Resource' does not contain a definition for 'Raw'. I have no idea where this error came from or how to fix it. There is a directory in Resource folder called raw. In it, there is a file named flushing.mp3. the VS intellisense does indicate the file is there. Any ideas are appreciated. TIA

Here is my code for my dependency service:

[assembly: Dependency(typeof(Audio))]
namespace PooperAppMobile.Droid.DependencyServices
{
    public class Audio : IAudio
    {
        private MediaPlayer _mediaPlayer;

        public bool PlayFlush()
        {
            _mediaPlayer = MediaPlayer.Create(global::Android.App.Application.Context, Resource.Raw.flushing);
            _mediaPlayer.Start();
            return true;
        }
    }
}
1
Ok, so I went and rebooted my pc and the problem has gone away for the moment. ugh.Wallace B. McClure

1 Answers

0
votes

Well to be quite honest this error was giving me quite a pain when I saw this solution on a GITHUB discussion now all you have to do is add this line in your project file i.e. the .csproj, in your debug property group something like this :

<PropertyGroup.......

<AndroidUseManagedDesignTimeResourceGenerator>False</AndroidUseManagedDesignTimeResourceGenerator>
....

</PropertyGroup>

And It will start working as expected,

Good luck!

In case of queries do revert.