How to fix 'FileNotFoundException: Could not load file or assembly' when try to subscribe COM event.

  • Thread starter Thread starter Vadik16
  • Start date Start date
V

Vadik16

Guest
When I subscribe to event of COM+ object I get error:

System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.EnterpriseServices
StackTrace:
at System.EnterpriseServices.IRemoteDispatch.RemoteDispatchNotAutoDone(String s)
at System.EnterpriseServices.RemoteServicedComponentProxy.Invoke(IMessage reqMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ComCalculator.Calculator.add_CalculatedEvent(CalculatedHandler value)
at ConsoleApp1.Program.Main(String[] args) in C:\Users\vekas\source\repos\ConsoleApp1\ConsoleApp1\Program.cs:line 66

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.


I create simple COM+ object and client application both on C#.

I register it via regsvcs and add it to GAC via gacutil.

COM+ object (dll library, .net framework 4.6.1):

[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(AccessChecksLevel = AccessChecksLevelOption.Application, Authentication = AuthenticationOption.None, ImpersonationLevel = ImpersonationLevelOption.Anonymous, Value = false)]
[assembly: ApplicationName("ComCalculator")]
[assembly: AssemblyKeyFile("ComCalculator.snk")]



[Guid("FB49CFF3-546F-43EC-B295-E59F8E09644F")]
[ComVisible(true)]
[ProgId("ComCalculator.Calculator")]
[ComSourceInterfaces(typeof(IEvents))]
[ClassInterface(ClassInterfaceType.None)]
[EventTrackingEnabled(true)]
public class Calculator : ServicedComponent, ICalculator
{
[ComVisible(false)]
public delegate void CalculatedHandler(string args);

public event CalculatedHandler CalculatedEvent;

[DispId(1)]
public int Sum(int a, int b)
{
if (CalculatedEvent != null)
CalculatedEvent("tet");
return a + b;
}
}

[Guid("5D71F0EB-EEFD-4FEC-9821-C6526E11DB7B")]
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ICalculator
{
[DispId(1)]
int Sum(int a, int b);
}

[Guid("A7487C90-11E6-4A4B-BA21-E43F0BCF89EF")]
[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IEvents
{
[DispId(1)]
void CalculatedEvent(string args);
}

Client:

ComCalculator.Calculator c = new ComCalculator.Calculator();
c.CalculatedEvent += new ComCalculator.Calculator.CalculatedHandler(C_CalculatedEvent); //error

I enabled Fusion Log and found this error in folder "dllhost.exe":

*** Assembly Binder Log Entry (9/19/2019 @ 3:16:09 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\WINDOWS\SysWOW64\dllhost.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/WINDOWS/SysWOW64/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1/ConsoleApp1.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1.EXE.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1/ConsoleApp1.EXE.
LOG: All probing URLs attempted and failed.



*** Assembly Binder Log Entry (9/19/2019 @ 3:16:09 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\WINDOWS\SysWOW64\dllhost.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = ConsoleApp1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/WINDOWS/SysWOW64/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = dllhost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1/ConsoleApp1.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1.EXE.
LOG: Attempting download of new URL file:///C:/WINDOWS/SysWOW64/ConsoleApp1/ConsoleApp1.EXE.
LOG: All probing URLs attempted and failed.

Continue reading...
 
Back
Top