Prevent application start fail if MSMQ not installed
Asked Answered
E

2

0

I'm using MSMQ in my .NET application. If MSMQ installed but not running - it can be handled.

But how to prevent crash on start up if MSMQ feature not installed on local machine ?

Estrone answered 16/4, 2013 at 10:32 Comment(0)
P
3

It's not pretty, but I've used this before with some success:

public static bool IsMsmqInstalled
{
    get
    {
        try
        {
            IntPtr result = NativeMethods.LoadLibrary("Mqrt.dll");
            return (result != IntPtr.Zero);
        }
        catch (Exception)
        {
            return false;
        }
    }
}

public sealed class NativeMethods
{
    [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
    internal static extern IntPtr LoadLibrary(string lpFileName);
}
Pestana answered 19/4, 2013 at 12:4 Comment(0)
J
2

Here's my blog:

How to tell if MSMQ is installed

Jesher answered 23/4, 2013 at 12:10 Comment(1)
Yes, but app crash even before start, then CLR try to load it (Estrone

© 2022 - 2024 — McMap. All rights reserved.