views:

1235

answers:

3

I'm attempting to instantiate a Windows Media Player COM object on my machine:

Guid mediaPlayerClassId = new Guid("47ac3c2f-7033-4d47-ae81-9c94e566c4cc");
Type mediaPlayerType = Type.GetTypeFromCLSID(mediaPlayerClassId);
Activator.CreateInstance(mediaPlayerType); // <-- this line throws

When executing that last line, I get the following error:

System.IO.FileNotFoundException was caught
  Message="Retrieving the COM class factory for component with CLSID {47AC3C2F-7033-4D47-AE81-9C94E566C4CC} failed due to the following error: 80070002."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
       at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at MyStuff.PreviewFile(String filePath) in F:\Trunk\PreviewHandlerHosting\PreviewHandlerHost.cs:line 60
  InnerException:

This same code works on other developer machines and end user machines. For some reason, it only fails on my machine. What could be the cause?

+2  A: 

Well, 0x80070002 means File not found, so I'd check to see whether the DLL pointed to in the COM registration actually exists on your machine

Paul Betts
It points to Windows Media Player COM object, which exists on my machine, of course, and runs fine...hmmm.
Judah Himango
+2  A: 

80070002 is a File Not Found error.

My guess is your machine is missing a dependency. Try running the com component through depends.exe to see if you have all of the required libraries installed.

Reed Copsey
Thanks for the suggestion. I'll run depends.exe and get back to you shortly.
Judah Himango
Thanks, that helped me track down the real problem. I'm marking yours as the answer.
Judah Himango
A: 

If application pool crashes this error can happen. You can check your code if there is any function or object initialization repeating more eventually. This can cause memory leakage and at last application pool crash

saknet