System.IO.FileNoteFoundException: Retrieving the COM class factory for the component

bryon 101 Reputation points
2022-10-04T13:03:56.26+00:00

I am trying to load an assembly (lets call it MyAssembly.dll) on a remote 32 bit machine. The assembly itself is a code wrapper that handles interop assemblies related to the local hardware on the machine, and the reason I want to do this is so that when this is deployed I can make direct calls to the assembly.

Here is a snippet, and source of the problem:

private static object LoadInstance(string path, string type)  
{  
   Assembly assembly = Assembly.LoadFrom(path);  
   return assembly.CreateInstance(typeName);  
}  

While it loads from the remote path, it will crash on the CreateInstance call. My thought is that the assembly I am loading cannot find the two dependancies. By the way - I did run an application directly on the remote computer and I was able to use the library.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'xxx.IO.xxxxx' threw an exception. ---> System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {8C6A0427-E3F2-11CF-B34A-00AA003C435E} failed due to the following error: 80070002 The system cannot find the file specified. (Exception from HRESULT: 0x80070002).
at xxx.IO.xxxxx..cctor()
--- End of inner exception stack trace ---
at xxx.IO.xxxxx..cctor()
--- End of inner exception stack trace ---
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName)
at someApp.Program.LoadInstance(String path, String typeName) in C:.....\Program.cs:line 58
at someApp.Program.Main(String[] args) in C:.....\Program.cs:line 41

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,285 questions
Remote Desktop
Remote Desktop
A Microsoft app that connects remotely to computers and to virtual apps and desktops.
4,294 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,557 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. bryon 101 Reputation points
    2022-10-04T18:24:38.293+00:00

    I found the issue with this. I was debugging another issue with a library that had a similar name to one of my dependencies. It is trying to load this assembly and it cannot find it because I removed the file. I found this by enabling fusion logs. So, I had to search my machine for any references to it, which I found in my registry.

    0 comments No comments