2

I have the following function that I am attempting to use to determine the length of an MP3 file:

public static string GetMP3DurationBackup(string Filename)
{
    string Duration = null;
    WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
    WMPLib.IWMPMedia m = w.newMedia(Filename);
    if (m != null)
    {
        Duration = m.durationString;
    }
    w.close();
    return Duration;
}

I have run into an issue where I get the following error:

Retrieving the COM class factory for component with CLSID {6BF52A52-394A-11D3-B153-00C04F79FAA6} failed due to the following error: 80040154..

when I call the above function from my web application (call below):

string test = MediaUtil.GetMP3DurationBackup(@"C:\Temp\Audio\bad.mp3");

But when I call it from a console application test harness I created (exact same call as above) it works fine. I have set the project that contains the function to target x86 in the Build properties, but that did not fix the issue.

Does anyone know why this would happen? Suggestions on where to start to debug this?

UPDATED FOR BOUNTY:

Ok, I've tried a number of things but I am still getting this error. Among other things I have tried the steps below which I felt were the most promising, but no dice:

  1. Went into my registry and confirmed that the value at: HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{6BF52A52-394A-11d3-B153-00C04F79FAA6}\InprocServer32 is refering to C:\WINDOWS\SysWOW64\wmp.dll
  2. Opened command prompt, navigated to C:\WINDOWS\SysWow64, ran: regsvr32.exe wmp.dll

I have created a console app test harness and I am able to reproduce the error if I run the test project in x64. If I switch it to x86 it works fine.

Does anyone have any idea of why the above would not resolve the issue? Suggestions on where to look next?

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
  • Have you ensured that your Application Pool has `Enable 32-bit Applications` set to True? – McCee Apr 17 '13 at 01:17
  • This is Windows Server 2003 running IIS 6. Is that an option under IIS 6? – Abe Miessler Apr 17 '13 at 01:23
  • Hmm good point. Try this? http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/405f5bb5-87a3-43d2-8138-54b75db73aa1.mspx?mfr=true – McCee Apr 17 '13 at 01:25
  • For posterity's sake, I'm recommenting with the actual steps on Windows Server 2003/IIS 6.0: Step 1) Open a command prompt and navigate to the %systemdrive%\Inetpub\AdminScripts directory. Step 2) Type the following command: cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “true” – McCee Apr 17 '13 at 01:38
  • 2
    Note the bitness (32 vs 64) is not determined by "the project that contains the function", but by the windows process executing the call. To make sure what's the bitness during the call, you can dump the value of IntPtr.Size in C# somewhere. If it's 8 (64-bit), you need to ensure wmd.dll is registered on the 64-bit side of the registry. If it's 4 (32-bit), you need to ensure wmd.dll is registered on the 32-bit side of the registry. – Simon Mourier Apr 17 '13 at 07:50
  • @SimonMourier, awesome idea with the `IntPtr.Size`, I'm going to add that to my bag of tricks. When I checked this it was 8. I had used regsvr32 to register the dll before, but it sounds like that will not work. How would I register on the 64 bit side of the registry? I tried regsvr and regsvr64, but neither of those exist. – Abe Miessler Apr 17 '13 at 15:25
  • Check out Liam's answer here: http://stackoverflow.com/questions/4897685/how-do-i-register-a-dll-on-windows-7-64-bit – Simon Mourier Apr 17 '13 at 15:27
  • @SimonMourier, I tried Liam's solution but I am still getting the same error. Any idea why this would happen? – Abe Miessler Apr 17 '13 at 16:27
  • @McCee, I tried those instructions and now IIS is down. The following error is being thrown in the event logs: `ISAPI Filter 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\\aspnet_filter.dll' could not be loaded due to configuration problem. The current configuration only supports loading images built for a x86 processor architecture.` – Abe Miessler Apr 17 '13 at 16:30
  • You an reverse the action by executing: `cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 “false”`. – McCee Apr 17 '13 at 16:36
  • Yeah I did that and got it back up and running. Is there a way to set the app pool to run both 32 and 64? – Abe Miessler Apr 17 '13 at 16:46
  • Would it be possible for me to find a 64 bit version of the DLL and use that instead? – Abe Miessler Apr 17 '13 at 16:55
  • You can't run 32 & 64-bit in the same process, no. I've tried your code in an ASP.NET 64-bit IIS app, and it works fine. Maybe you could try to repair Media Player, or use SysInternal's ProcMon to track registry call and determine what is the COM's CLSID that is not registered. – Simon Mourier Apr 17 '13 at 20:06
  • @SimonMourier, don't I already have the CLSID from the error message? – Abe Miessler Apr 17 '13 at 20:42
  • Yes you do, so you can check where the whole thing's failing using procmon. – Simon Mourier Apr 17 '13 at 21:27
  • @SimonMourier, do you have any recommendations on what to look for in procmon? I have found a few references to the CLSID in there. Most of them say `SUCCESS`, but there are a few that say `NAME NOT FOUND`. Can idea on what I should be looking for in these? – Abe Miessler Apr 18 '13 at 15:43
  • Well, the same query should give the same result. If the key is not found, that confirms there is some setup or access right issue. – Simon Mourier Apr 18 '13 at 16:01
  • @SimonMourier, I'm sorry to keep bothering your about this but is there any chance you could expand on what I would need to do to resolve this? I have have very little experience with procmon and I have no idea where to look to find the cause of the setup or access right issue. Thank you again for all your help, and I'm sorry to keep bugging you about this. I've spent the whole week trying to resolve this and it's starting to drive me nuts. – Abe Miessler Apr 19 '13 at 19:06
  • Have you tried to repair media player, or maybe reinstall it? Things like http://www.thewindowsclub.com/repair-windows-media-player-with-fix-wmp-utility or http://support.microsoft.com/mats/windows_media_player_diagnostic/ – Simon Mourier Apr 20 '13 at 06:13
  • @AbeMiessler: Not sure if it helps, but I've seen similar problems with other COM components: Can you remove the WMPLib reference from your project, readd it, right-click it, choose `Properties` and set `Embed Interop Types` and `Isolated` to `false` and `Local copy` to `true`? – Carsten Apr 24 '13 at 11:57
  • OFF: go for e.g. http://www.un4seen.com/ instead. anything but wmp to get less headaches... –  Apr 25 '13 at 07:17

2 Answers2

2

You say it doesn't work in x64, but you try to register the 32-bit version of wmp.dll (C:\Windows\SysWow64 contains 32-bit assemblies).

Try to register the x64 version of wmp.dll, which is located in C:\Windows\System32 on a 64-bit platform.

If you don't have this file then there probably is no 64bit Windows Media Player available for your platform. But there is a workaround:

Create a 32-bit console application that takes the mp3 filename as command line argument and outputs the duration to stdout using Console.WriteLine, then in the webapp, you call the console application and capture the output like in this example on MSDN

huysentruitw
  • 27,376
  • 9
  • 90
  • 133
0

Give this lib a whirl. Its fast and has no special requirements for software to be installed on the machine.

http://naudio.codeplex.com/

iamkrillin
  • 6,798
  • 1
  • 24
  • 51