使用 NetworkInterface.GetAllNetworkInterfaces()后,打开设计器报:内存位置访问无效,该如何解决

使用 NetworkInterface.GetAllNetworkInterfaces()后,打开设计器报:内存位置访问无效
以下是我获取适配器代码,winform,VS2012
            var nics = NetworkInterface.GetAllNetworkInterfaces();
            foreach (var ni in nics)
            {
                IPInterfaceProperties property = ni.GetIPProperties();
                foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
                {
                    if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        DicAllIPV4List.Add(ni.Name, ip.Address.ToString());
                    }
                }
            }

但使用后,编译正确,但打开设计器报:内存位置访问无效,求大神
使用 NetworkInterface.GetAllNetworkInterfaces()后,打开设计器报:内存位置访问无效,该如何解决
------解决思路----------------------
别把代码写进Designer里