Solace Community is getting a facelift!
On March 3rd we will be starting the process of migrating Solace Community to a new platform. As a result, Solace Community will go in to a temporary read-only state. You will still be able to come onto Solace Community and search through posts to find answers, but you won't be able to ask questions, post comments, or react in any way.
We hope to have the migration complete by Wednesday March 5th (or sooner), so please keep an eye out!
.NET - Context.Init throws exception when used with dependency injecetion

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 callsContextFactory.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!
Comments
-
Hi @John, interesting. I can't see anything wrong with calling Init the way you do but I wouldn't describe my opinion as definitive on that. I'm interested in your logging delegate - if you don't set the delegate, do you still get the same error?
1 -
I think we found out a fix to the issue. Though I am still a bit confused as to why it threw the exception in this part of the application.
I went to
Tools > Options > Projects and Solutions > Web Projects
and checkedUse the 64 bit version of IIS Express for web sites and projects
This just worked and I am not really sure why.
Found this fix here: https://stackoverflow.com/questions/5229310/system-badimageformatexception-could-not-load-file-or-assemblyNot even sure if it was an error with Solace per se, just happened to be where this occurred maybe?
0