Hi!
I am trying to setup a .NET Framework 4.7.2 application for publishing to an Solace Event Broker.
I have made a class with the role to configure and contain the SolaceContext and provide it whenever I’d like to create a session to publish a message.
public class SolaceContextContainer : ISolaceContextContainer
{
private readonly IContext _context;
public SolaceContextContainer()
{
_context = CreateContext();
}
public IContext GetContext()
{
return _context;
}
private IContext CreateContext()
{
ConfigureContext();
return ContextFactory.Instance.CreateContext(new ContextProperties(), null);
}
private void ConfigureContext()
{
var contextFactoryProperties = new ContextFactoryProperties()
{
SolClientLogLevel = SolLogLevel.Warning
};
contextFactoryProperties.LogToConsoleError();
contextFactoryProperties.LogDelegate = info => LogManager.GetLogger(GetType()).Info(LogMessage.Create(info.ToString()));
try
{
ContextFactory.Instance.Init(contextFactoryProperties);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
My problem is that an exception when the instance of this class is created and it calls
ContextFactory.Instance.Init(contextFactoryProperties);
Error encountered in interop adapter An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) In method: Init | System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at SolaceSystems.Solclient.Messaging.Native.Interop.SolaceNativeAPI.LogSetCallback(LogCallbackHandler callback, IntPtr user)
at SolaceSystems.Solclient.Messaging.Native.MAdapter.MSolClientSetLogCallback(LogCallbackHandler callback, IntPtr user)
I have tried googling around but it everything I find says it has to do with CPU build targets or the like and that seems wierd.
Further, I get a working context in a test method in the same solution, where I manage to publish messages successfully to the Solace Cloud.
Can this be due to calling Init during when the instance of my container class is created?
Is this a stupid way of handling the context?
Thankful for any help!