Last post Jul 24, 2020 07:07 AM by Peng Ding
Jul 08, 2020 06:18 AMfirstname.lastname@example.org|LINK
i get error on high lighted code
using Microsoft.Web.Administration;ServerManager serverManager = new ServerManager();
//get the site (e.g. default)
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "ERP3");
//Protocol hhtp, https....
i get error on that high light
object reference not set to an instance object
Jul 08, 2020 06:49 AM|PatriceSc|LINK
It happens when you try to call use an object property or method for an object which is null. Use the debugger (or add code checks) to see which object in your expression is null starting maybe with site.
Jul 08, 2020 07:38 AMemail@example.com|LINK
my demo don't have any problem with c# console but when i run it on asp.net web service i get this exception
Jul 08, 2020 08:38 AM|PatriceSc|LINK
If you can't debug live you can add code such as :
if (site==null) throw new Exception("site is null");
if (site.Binbings==null) throw new Exception("Bindings is null");
to find out which object is causing the issue. EndPoint is perhaps null if not binding is explicitely defined. Ypu may want also to handle having 0 to n bindings for your site etc...
Jul 08, 2020 08:54 AMfirstname.lastname@example.org|LINK
i have exception at both of them
if (site.Bindings == null) throw new Exception("Bindings is null");
if (site == null) throw new Exception("site is null");
Jul 08, 2020 09:03 AMemail@example.com|LINK
can you run that demo at the first post on your side on asp.net web service?
Jul 24, 2020 07:07 AM|Peng Ding|LINK
HttpContext.Current only exists in the context of the Web application, the client does not exist HttpContext,You need to make sure that httpcontext is on the server and not the client.