MQ

MQ

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception only in ASP.Net web application

  • 1.  The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception only in ASP.Net web application

    Posted Wed September 11, 2024 01:47 AM
    Edited by Frank Martin Wed September 11, 2024 02:23 AM

    MQ client 7.5 is already installed on machine and is primary. Then installed MQ client 9.1.4 but didn't make it primary so now this machine has both clients where 7.5 is primary.

    Name:        WebSphere MQ
    Version:     7.5.0.6
    Level:       p750-006-160226
    BuildType:   IKAP - (Production)
    Platform:    WebSphere MQ for Windows
    Mode:        32-bit
    O/S:         Windows Ver 6.2 (7) Server Standard x64 Edition, Build 9200
    InstName:    Installation1
    InstDesc:
    Primary:     Yes
    InstPath:    C:\Program Files (x86)\IBM\WebSphere MQ
    DataPath:    C:\Program Files (x86)\IBM\WebSphere MQ
    MaxCmdLevel: 750
    
    Name:        WebSphere MQ
    Version:     9.1.4.0
    InstName:    MQ9client
    InstDesc:    mq9.1
    InstPath:    C:\Program Files\IBM\MQ9Client
    Primary:     No
    

    We want to keep 7.5 as primary while we migrate applications to 9.1.4 one by one. For that I created the following environment variable and also added entry in config file of my applications.

    Environment Variable

    DEVPATH  
    C:\Program Files\IBM\MQ9client\bin
    

    Config Entry

    <runtime>
        <developmentMode developerInstallation="true"/>
      </runtime>
    

    After that I changed my applications to start using MQ 9.1.4 BUT there is a problem and that is only desktop applications are working fine while all web based application in ASP.Net are throwing this error:

    The type initializer for 'IBM.WMQ.Nmqi.UnmanagedNmqiMQ' threw an exception
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Stack Trace

    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at IBM.WMQ.Nmqi.NmqiEnvironment.GetInstance(String name)
       at IBM.WMQ.Nmqi.NmqiEnvironment.GetMQI(Int32 id)
       at IBM.WMQ.MQQueueManager.Connect(String queueManagerName)
       at IBM.WMQ.MQQueueManager..ctor(String queueManagerName, Hashtable properties)
       at WebApplicationNewMW.Middleware.CreateQueueManager() in c:\Documents\Visual Studio 2013\Projects\WebApplication\WebApplication\Middleware.cs:line 43
       at WebApplicationNewMW.Default.Page_Load(Object sender, EventArgs e) in c:\Documents\Visual Studio 2013\Projects\WebApplication\WebApplication\Default.aspx.cs:line 17
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    has context menu

    Whether I use IISExpress or IIS the issue happens with both. Any idea why desktop based applications work but not web based?



    ------------------------------
    Frank Martin
    ------------------------------



  • 2.  RE: The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception only in ASP.Net web application

    Posted Thu September 12, 2024 01:33 AM

    Because for a desktop application you can initialize the environment with setmqenv whereas IIS runs a a service. Create a startup file for IIS that initializes the environment with 

    call <path to mq binaries>\setmqenv -s 
    
    example
    call "c:\program files (x86)\WebSphere MQ\bin\setmqenv" -s
    ..... start IIS here

    Hope it helps



    ------------------------------
    Francois Brandelik
    ------------------------------



  • 3.  RE: The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception only in ASP.Net web application

    Posted Thu September 12, 2024 02:26 AM

    If I use setmqenv -s, will it set the environment for all applications including the ones that currently use MQ 7.5?

    Because I want existing applications to continue to use MQ 7.5 while I move each application one by one to MQ 9.1.4



    ------------------------------
    Frank Martin
    ------------------------------



  • 4.  RE: The type initializer for 'IBM.WMQ.Nmqi.BindingsNmqiMQ' threw an exception only in ASP.Net web application

    Posted Thu September 12, 2024 08:07 AM

    setmqenv will only affect the session (dos) you are running it in. As for IIS, you cannot mix mq versions. If you want to connect to different versions of MQ, choose the higher one and just know not to use any of the new features when connecting to a lower environment. If you want to use different versions you will need different instances of IIS, each running its own setmqenv 

    Hope this clarifies



    ------------------------------
    Francois Brandelik
    ------------------------------