Can't instantiate COM component in C# - error 80070002

13,604

Solution 1

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.

Solution 2

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

Solution 3

Further possibly helpful info. We saw this issue on a classic asp web app which loads .net components. one app was fine, another was not. Same machine? So what gives? We weren't getting proper errors around failing to load a com component, just the error number 0x80070002.

Eventually this was fixed by just setting the app pool of the broken app to the same as the working app. Something about the app pool meant that the component couldn't be loaded properly, same identity etc (iis 6).

There were a bunch of old version numbers in the registry for that component, but regasm always does that, it's terrible at cleaning up, we've even had to write a little tool to delete them all when moving between version numbers on dev machines. But in this instance, those version numbers weren't the issue.

Conclusion: sounds like a permissions problem, but what do i know..

Share:
13,604
Judah Gabriel Himango
Author by

Judah Gabriel Himango

Web developer, speaker, entrepreneur, startup founder, musician, dad, husband, Jewish follower of Jesus. I created Youth Service Network's YsnMN. It's an awesome project to help homeless youth in Minnesota. I blogged about it here, and that blog post made it to the front page of HackerNews - woohooo!) I created Chavah, a Pandora-like PWA for the Messianic Jewish religious community. I'm a RavenDB enthusiast and helped create Raven Studio. I help run Twin Cities Code Camp and built TwinCitiesCodeCamp.com. I built 3M's Visual Attention Software. I'm the creator of MessianicChords.com, an ad-free HTML5 site for lyrics and guitar chords to Messianic Jewish music. I built EtzMitzvot.com, a fun project visualizing the relationship between commandments in the Hebrew Bible. I blog about software at DebuggerDotBreak, and on life and faith over at Kineti.

Updated on June 04, 2022

Comments

  • Judah Gabriel Himango
    Judah Gabriel Himango almost 2 years

    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?

    • overslacked
      overslacked over 14 years
      I wish you'd posted what the problem was, to help others who arrive here later....
    • Judah Gabriel Himango
      Judah Gabriel Himango over 14 years
      The problem turned out to be something really specific to our company. Basically, our software had installed a Windows Media preview handler that later was uninstalled, but left some registry keys in place. This preview handler was gone - hence File Not Found error - but some registry keys were left, causing this issue.
    • overslacked
      overslacked over 14 years
      Thanks very much for the update! I've been up and down a server we're having this same error on ... I'll take any details, no matter how abstract or useless seeming they are.
    • Judah Gabriel Himango
      Judah Gabriel Himango over 14 years
      If I recall right, I searched the registry for the ID, then looked up the object in OleView. From there, I started to realize it was pointing to a preview handler for an old Windows Media Player format we had been using. Deleting that component from the registry fixed the issue.
  • Judah Gabriel Himango
    Judah Gabriel Himango almost 15 years
    It points to Windows Media Player COM object, which exists on my machine, of course, and runs fine...hmmm.
  • Judah Gabriel Himango
    Judah Gabriel Himango almost 15 years
    Thanks for the suggestion. I'll run depends.exe and get back to you shortly.
  • Judah Gabriel Himango
    Judah Gabriel Himango almost 15 years
    Thanks, that helped me track down the real problem. I'm marking yours as the answer.