I have an ASP.NET Web API hosted in a cloud service web role. I have added a WebRole class extending RoleEntryPoint which is attempting to retrieve an IoC castle Windsor container which has dependencies setup in the StartUp.cs of my web API. I want to then retrieve a logger instance I have registered and use that in my WebRole.
public class WebRole : RoleEntryPoint
{
private ICancellationTokenSourceProvider _cancellationTokenSourceProvider;
public override bool OnStart()
{
try
{
var container = IoC.GetContainer();
_cancellationTokenSourceProvider = container.Resolve<ICancellationTokenSourceProvider>();
}
catch (Exception)
{
throw;
}
return base.OnStart();
}
However when I try to deploy this to the cloud service I get the following exception:
Unhandled Exception: Unable to find assembly 'Castle.Windsor, Version=3.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc'. at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.DeserializeObject(MemoryStream stm) at System.AppDomain.Deserialize(Byte[] blob) at System.AppDomain.UnmarshalObject(Byte[] blob) ' [2020-06-19T16:48:01Z] Last exit time: [2020/06/19, 16:48:05.617]. Last exit code: 0.
I have tried to find the cause and solution to this extensively.
- I have tried to add binding redirects to the missing assembly in MyApi.dll.config and ensuring it is set to copy always.
- I have also ensured the assembly has Copy Local set to true as well.
However, I still get this error every time and the web role keeps restarting trying to recover from this exception.