NetworkInterface.GetAllNetworkInterfaces causes Invalid access to memory location












0















I have this piece of code to get a NetworkInterface with a specific name:



string myIf = "Local Area Connection";
NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => i.Name == myIf);


However, this throws a NetworkInformationException: Invalid access to memory location with an ErrorCode of 998 (which means exactly the same as the exception says).



System.Net.NetworkInformation.NetworkInformationException was unhandled  
ErrorCode=998
HResult=-2147467259
Message=Invalid access to memory location
NativeErrorCode=998
Source=System
StackTrace:
at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces()
at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
at MyApp.CheckIfNetworkOnline(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
InnerException:


.NET documentation claims that this is due to "A Windows system function call failed" or "when a call to a Win32 function fails".



This is on .NET 4.5.2, the network interface does exist, and the application is already running as Administrator.



What can cause this exception to appear, and is there anything that can be done to fix it?










share|improve this question

























  • Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

    – Jeroen Mostert
    Jun 2 '17 at 15:20











  • @ScottChamberlain Done!

    – GTHvidsten
    Jun 2 '17 at 15:21











  • If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

    – Jeroen Mostert
    Jun 2 '17 at 15:24













  • @JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

    – GTHvidsten
    Jun 2 '17 at 15:35











  • Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

    – Hans Passant
    Jun 2 '17 at 15:55


















0















I have this piece of code to get a NetworkInterface with a specific name:



string myIf = "Local Area Connection";
NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => i.Name == myIf);


However, this throws a NetworkInformationException: Invalid access to memory location with an ErrorCode of 998 (which means exactly the same as the exception says).



System.Net.NetworkInformation.NetworkInformationException was unhandled  
ErrorCode=998
HResult=-2147467259
Message=Invalid access to memory location
NativeErrorCode=998
Source=System
StackTrace:
at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces()
at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
at MyApp.CheckIfNetworkOnline(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
InnerException:


.NET documentation claims that this is due to "A Windows system function call failed" or "when a call to a Win32 function fails".



This is on .NET 4.5.2, the network interface does exist, and the application is already running as Administrator.



What can cause this exception to appear, and is there anything that can be done to fix it?










share|improve this question

























  • Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

    – Jeroen Mostert
    Jun 2 '17 at 15:20











  • @ScottChamberlain Done!

    – GTHvidsten
    Jun 2 '17 at 15:21











  • If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

    – Jeroen Mostert
    Jun 2 '17 at 15:24













  • @JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

    – GTHvidsten
    Jun 2 '17 at 15:35











  • Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

    – Hans Passant
    Jun 2 '17 at 15:55
















0












0








0








I have this piece of code to get a NetworkInterface with a specific name:



string myIf = "Local Area Connection";
NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => i.Name == myIf);


However, this throws a NetworkInformationException: Invalid access to memory location with an ErrorCode of 998 (which means exactly the same as the exception says).



System.Net.NetworkInformation.NetworkInformationException was unhandled  
ErrorCode=998
HResult=-2147467259
Message=Invalid access to memory location
NativeErrorCode=998
Source=System
StackTrace:
at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces()
at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
at MyApp.CheckIfNetworkOnline(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
InnerException:


.NET documentation claims that this is due to "A Windows system function call failed" or "when a call to a Win32 function fails".



This is on .NET 4.5.2, the network interface does exist, and the application is already running as Administrator.



What can cause this exception to appear, and is there anything that can be done to fix it?










share|improve this question
















I have this piece of code to get a NetworkInterface with a specific name:



string myIf = "Local Area Connection";
NetworkInterface ni = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(i => i.Name == myIf);


However, this throws a NetworkInformationException: Invalid access to memory location with an ErrorCode of 998 (which means exactly the same as the exception says).



System.Net.NetworkInformation.NetworkInformationException was unhandled  
ErrorCode=998
HResult=-2147467259
Message=Invalid access to memory location
NativeErrorCode=998
Source=System
StackTrace:
at System.Net.NetworkInformation.SystemNetworkInterface.GetNetworkInterfaces()
at System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
at MyApp.CheckIfNetworkOnline(Object state)
at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.TimerQueue.FireNextTimers()
at System.Threading.TimerQueue.AppDomainTimerCallback()
InnerException:


.NET documentation claims that this is due to "A Windows system function call failed" or "when a call to a Win32 function fails".



This is on .NET 4.5.2, the network interface does exist, and the application is already running as Administrator.



What can cause this exception to appear, and is there anything that can be done to fix it?







c# .net winapi network-interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 2 '17 at 15:21







GTHvidsten

















asked Jun 2 '17 at 15:13









GTHvidstenGTHvidsten

1,10111034




1,10111034













  • Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

    – Jeroen Mostert
    Jun 2 '17 at 15:20











  • @ScottChamberlain Done!

    – GTHvidsten
    Jun 2 '17 at 15:21











  • If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

    – Jeroen Mostert
    Jun 2 '17 at 15:24













  • @JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

    – GTHvidsten
    Jun 2 '17 at 15:35











  • Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

    – Hans Passant
    Jun 2 '17 at 15:55





















  • Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

    – Jeroen Mostert
    Jun 2 '17 at 15:20











  • @ScottChamberlain Done!

    – GTHvidsten
    Jun 2 '17 at 15:21











  • If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

    – Jeroen Mostert
    Jun 2 '17 at 15:24













  • @JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

    – GTHvidsten
    Jun 2 '17 at 15:35











  • Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

    – Hans Passant
    Jun 2 '17 at 15:55



















Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

– Jeroen Mostert
Jun 2 '17 at 15:20





Install LINQPad and see if simply evaluating the expression NetworkInterface.GetAllNetworkInterfaces() is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See if netsh interface show interface shows anything funky.

– Jeroen Mostert
Jun 2 '17 at 15:20













@ScottChamberlain Done!

– GTHvidsten
Jun 2 '17 at 15:21





@ScottChamberlain Done!

– GTHvidsten
Jun 2 '17 at 15:21













If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

– Jeroen Mostert
Jun 2 '17 at 15:24







If, as your method name suggests, you are merely interested in whether a network is available, you may want to use GetIsNetworkAvailable instead. You cannot, in general, rely on the appropriate connection being named "Local Area Connection". (On my machine, it's called "Ethernet", but really, it could be anything. All you should care about is that it's not a loopback or tunnel interface and leave the rest to the route table.)

– Jeroen Mostert
Jun 2 '17 at 15:24















@JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

– GTHvidsten
Jun 2 '17 at 15:35





@JeroenMostert I can't use GetIsNetworkAvailable because there are several network interfaces on this PC, and I need to check if one particular interface is available and up, not if any interface is up.

– GTHvidsten
Jun 2 '17 at 15:35













Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

– Hans Passant
Jun 2 '17 at 15:55







Error code 998 is very, very nasty. The DllMain entrypoint of an unmanaged DLL failed with an AccessViolationException. Very much a dirty machine problem, so you'd start by trying this on another machine to verify that this only happens on this one. Then it could be useful to unable unmanaged debugging and forcing the debugger to stop on a Win32 exception, helps you identify the specific DLL. Tinkering with the installed anti-malware product tends to be useful.

– Hans Passant
Jun 2 '17 at 15:55














1 Answer
1






active

oldest

votes


















0














I had the same issue with my 32-bit site and following steps solved my problem.




  1. Open IIS

  2. Expand your machine name on the left

  3. Select "Application Pools"

  4. Select the Application Pool of your site

  5. On the right in the actions select "Advanced Settings"

  6. In the General Change "Enable 32-Bit Applications" to false and press OK

  7. On the right in the actions select "Advanced Settings" again.

  8. In the General Change "Enable 32-Bit Applications" to true and press OK






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44332200%2fnetworkinterface-getallnetworkinterfaces-causes-invalid-access-to-memory-locatio%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I had the same issue with my 32-bit site and following steps solved my problem.




    1. Open IIS

    2. Expand your machine name on the left

    3. Select "Application Pools"

    4. Select the Application Pool of your site

    5. On the right in the actions select "Advanced Settings"

    6. In the General Change "Enable 32-Bit Applications" to false and press OK

    7. On the right in the actions select "Advanced Settings" again.

    8. In the General Change "Enable 32-Bit Applications" to true and press OK






    share|improve this answer




























      0














      I had the same issue with my 32-bit site and following steps solved my problem.




      1. Open IIS

      2. Expand your machine name on the left

      3. Select "Application Pools"

      4. Select the Application Pool of your site

      5. On the right in the actions select "Advanced Settings"

      6. In the General Change "Enable 32-Bit Applications" to false and press OK

      7. On the right in the actions select "Advanced Settings" again.

      8. In the General Change "Enable 32-Bit Applications" to true and press OK






      share|improve this answer


























        0












        0








        0







        I had the same issue with my 32-bit site and following steps solved my problem.




        1. Open IIS

        2. Expand your machine name on the left

        3. Select "Application Pools"

        4. Select the Application Pool of your site

        5. On the right in the actions select "Advanced Settings"

        6. In the General Change "Enable 32-Bit Applications" to false and press OK

        7. On the right in the actions select "Advanced Settings" again.

        8. In the General Change "Enable 32-Bit Applications" to true and press OK






        share|improve this answer













        I had the same issue with my 32-bit site and following steps solved my problem.




        1. Open IIS

        2. Expand your machine name on the left

        3. Select "Application Pools"

        4. Select the Application Pool of your site

        5. On the right in the actions select "Advanced Settings"

        6. In the General Change "Enable 32-Bit Applications" to false and press OK

        7. On the right in the actions select "Advanced Settings" again.

        8. In the General Change "Enable 32-Bit Applications" to true and press OK







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '18 at 5:44









        vahidvahid

        1364




        1364






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44332200%2fnetworkinterface-getallnetworkinterfaces-causes-invalid-access-to-memory-locatio%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)