Search code examples
c#uwpwindows-media-player

Windows 11 UWP app throws FileNotFoundException on Windows.Media.Playback.MediaPlayer constructor


I am debugging a problem on my Xamarin.Forms.UWP app. I have multiple windows 11 machines where my program works fine when I install it from the windows store, but on machines from another vendor (with maybe a different windows image??) the program crashes with

'The specified module could not be found. (Exception from HRESULT: 0x8007007E)'.

I have traced the problem to the following call:

var x = new MediaPlayer();

A new UWP app with just this line crashes the same way, so it is not my app.

This MediaPlayer class comes from the Windows.Media.Playback namespace, and this seems to live in a filelocation that exists: C:\Program Files (x86)\Windows Kits\10\References\10.0.22621.0\Windows.Foundation.UniversalApiContract\15.0.0.0\Windows.Foundation.UniversalApiContract.winmd

Windows media player might be completely unrelated to this library, but as a test I downloaded windows mediaplayer from the windows store (Windows 11 no longer has windows media player embedded in it). When I try to open the program it says

'media player cannot start. Media player does not work due to a lack of media framework.'

Maybe this is related to my problem. Searching for this i find articles related to enabling the windows feature 'windows features\windows media player' but this is not available on this box.

Any idea what windows component I need to repair/update/install to make this work?

The windows version on the problem box is 23H2, all updates installed.


Solution

  • @Raymond was absolutely right.

    It was a windows 11 pro N install missing the 'Media Feature Pack', which you can add by going to System -> Optional Features.

    Thank you for the quick answer. That fixed it.