I have a base abstract class that exists in a nuget package that I am implementing a concrete class for, something like this:
public class MyConcreteClass : MyBaseAbstractClass<SomeType> {
public MyConcreteClass(IAnInterfaceOne interfaceOne, IAnInterfaceTwo interfaceTwo) : base(interfaceOne, interfaceTwo) { }
}
I am mocking the two parameters like so:
var mockFirst = new Mock<IAnInterfaceOne>();
var mockSecond = new Mock<IAnInterfaceTwo>();
and the concrete class like so:
var mockConcrete = new Mock<MyConcreteClass>(mockFirst.Object, mockSecond.Object);
When I try to access the Object
property within mockConcrete
var concreteObjectInstance = mockConcrete.Object
I get a FileNotFoundException
, Could not load file or assembly 'Serilog.dll'
and the debugger in VS points to the base constructor call for where the exception is coming from:
base(interfaceOne, interfaceTwo)
Castle.Core
and Moq
versions:
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Moq" version="4.5.21" targetFramework="net452" />
I have searched through the nuget package where the base class resides in and there are no references or usages of serilog. I searched Castle.Core
's repo and found many usages of serilog which I believe is a logging library. So I am a bit confused on how this exception is occuring and how I can try to resolve it so it does not throw the exception when I mock my object.
After digging through I found the cause of the problem. It actually is not related to castle or moq. It was actually caused by Metrics.NET which is a nuget package being referenced in MyBaseAbstractClass<T>
. This line was in the base class:
private readonly Metrics.Timer _callTimer = Metric.Timer("", Unit.Calls, SamplingType.LongTerm, TimeUnit.Milliseconds);
and the exception was being thrown every time the base class was initialized on that line. I looked at the packages Metrics.NET
was referencing and saw LibLog
. So I looked into LibLog
and saw it was referencing Serilog
. So I am not sure why Serilog
cannot be found within those packages still, but I removed the line throwing the exception since it was unused anyways and also removed the Metrics.NET
package. I am answering my question to make sure people know it is not a problem with Castle or Moq like I originally thought it was.