NetworkInterface.GetAllNetworkInterfaces causes Invalid access to memory location
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
add a comment |
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
Install LINQPad and see if simply evaluating the expressionNetworkInterface.GetAllNetworkInterfaces()
is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See ifnetsh 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 useGetIsNetworkAvailable
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 useGetIsNetworkAvailable
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
add a comment |
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
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
c# .net winapi network-interface
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 expressionNetworkInterface.GetAllNetworkInterfaces()
is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See ifnetsh 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 useGetIsNetworkAvailable
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 useGetIsNetworkAvailable
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
add a comment |
Install LINQPad and see if simply evaluating the expressionNetworkInterface.GetAllNetworkInterfaces()
is already problematic. If so, you may have a network driver that isn't playing nice in all circumstances. See ifnetsh 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 useGetIsNetworkAvailable
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 useGetIsNetworkAvailable
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
add a comment |
1 Answer
1
active
oldest
votes
I had the same issue with my 32-bit site and following steps solved my problem.
- Open IIS
- Expand your machine name on the left
- Select "Application Pools"
- Select the Application Pool of your site
- On the right in the actions select "Advanced Settings"
- In the General Change "Enable 32-Bit Applications" to false and press OK
- On the right in the actions select "Advanced Settings" again.
- In the General Change "Enable 32-Bit Applications" to true and press OK
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
I had the same issue with my 32-bit site and following steps solved my problem.
- Open IIS
- Expand your machine name on the left
- Select "Application Pools"
- Select the Application Pool of your site
- On the right in the actions select "Advanced Settings"
- In the General Change "Enable 32-Bit Applications" to false and press OK
- On the right in the actions select "Advanced Settings" again.
- In the General Change "Enable 32-Bit Applications" to true and press OK
add a comment |
I had the same issue with my 32-bit site and following steps solved my problem.
- Open IIS
- Expand your machine name on the left
- Select "Application Pools"
- Select the Application Pool of your site
- On the right in the actions select "Advanced Settings"
- In the General Change "Enable 32-Bit Applications" to false and press OK
- On the right in the actions select "Advanced Settings" again.
- In the General Change "Enable 32-Bit Applications" to true and press OK
add a comment |
I had the same issue with my 32-bit site and following steps solved my problem.
- Open IIS
- Expand your machine name on the left
- Select "Application Pools"
- Select the Application Pool of your site
- On the right in the actions select "Advanced Settings"
- In the General Change "Enable 32-Bit Applications" to false and press OK
- On the right in the actions select "Advanced Settings" again.
- In the General Change "Enable 32-Bit Applications" to true and press OK
I had the same issue with my 32-bit site and following steps solved my problem.
- Open IIS
- Expand your machine name on the left
- Select "Application Pools"
- Select the Application Pool of your site
- On the right in the actions select "Advanced Settings"
- In the General Change "Enable 32-Bit Applications" to false and press OK
- On the right in the actions select "Advanced Settings" again.
- In the General Change "Enable 32-Bit Applications" to true and press OK
answered Nov 18 '18 at 5:44
vahidvahid
1364
1364
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 ifnetsh 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