WgServerforWindows
WgServerforWindows copied to clipboard
Specified cast is not valid
When I try to activate internet sharing I have this error
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Specified cast is not valid. at NETCONLib.NetSharingManagerClass.get_INetSharingConfigurationForINetConnection(INetConnection pNetConnection) at WireGuardServerForWindows.Models.InternetSharingPrerequisite.<>c__DisplayClass5_0.<Resolve>b__1(INetConnection n) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 62 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at WireGuardServerForWindows.Models.InternetSharingPrerequisite.Resolve(String networkToShare) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 60 at WireGuardServerForWindows.Models.InternetSharingPrerequisite.Resolve() in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 51 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at GalaSoft.MvvmLight.Helpers.WeakAction.Execute() at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter) at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
System.InvalidCastException: Specified cast is not valid. at NETCONLib.NetSharingManagerClass.get_INetSharingConfigurationForINetConnection(INetConnection pNetConnection) at WireGuardServerForWindows.Models.InternetSharingPrerequisite.<>c__DisplayClass5_0.<Resolve>b__1(INetConnection n) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 62 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at WireGuardServerForWindows.Models.InternetSharingPrerequisite.Resolve(String networkToShare) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 60 at WireGuardServerForWindows.Models.InternetSharingPrerequisite.Resolve() in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\InternetSharingPrerequisite.cs:line 51
Hi @JLesuperb, it's a slightly different error message, but can you try the workaround described in the README here: https://github.com/micahmo/WireGuardServerForWindows#inability-to-enable-internet-sharing
Also keep an eye on #18. That enhancement should hopefully alleviate the issues related to Internet Sharing.
were you able to fix it? I have the same problem and I already tried to do it manually, it activates it but it does not share the internet
Hey! fixed it, make sure port 51820 is open on your router and then share the internet manually
Hi @JLesuperb, I am trying to clean up old issues, and I was wondering if you are still using WS4W and/or if you are still experiencing this issue? Since your original comment, there is an alternative way to share the server's internet connection with your WireGuard peers via NAT Routing which is more consistent than Persistent Internet Sharing. Let me know!