Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型为';System.NullReferenceException';在myproject.DLL中发生,但未在用户代码中处理_C#_Mobile Website - Fatal编程技术网

C# 类型为';System.NullReferenceException';在myproject.DLL中发生,但未在用户代码中处理

C# 类型为';System.NullReferenceException';在myproject.DLL中发生,但未在用户代码中处理,c#,mobile-website,C#,Mobile Website,这个错误是什么意思?我不断地得到这个错误,它过去工作正常,它刚刚开始抛出这个错误。。。。有什么帮助吗 img1.ImageUrl = ConfigurationManager.AppSettings.Get("Url").Replace("###", randomString) + Server.UrlEncode(((System.Web.UI.MobileControls.Form)Page.FindControl("mobileForm")).Title); 中发生“System.N

这个错误是什么意思?我不断地得到这个错误,它过去工作正常,它刚刚开始抛出这个错误。。。。有什么帮助吗

img1.ImageUrl = ConfigurationManager.AppSettings.Get("Url").Replace("###", randomString) 
 + Server.UrlEncode(((System.Web.UI.MobileControls.Form)Page.FindControl("mobileForm")).Title);
中发生“System.NullReferenceException”类型的异常 MyProject.DLL,但未在用户代码中处理

其他信息:对象引用未设置为 反对


这意味着在调用链中的某个位置,您试图访问
null
对象的属性或调用该对象的方法

根据你的陈述:

img1.ImageUrl = ConfigurationManager
                    .AppSettings
                    .Get("Url")
                    .Replace("###", randomString) 
                + Server.UrlEncode(
                      ((System.Web.UI.MobileControls.Form)Page
                      .FindControl("mobileForm"))
                      .Title);
我猜对
AppSettings.Get(“Url”)
的调用返回null是因为找不到该值,或者对
Page.FindControl(“mobileForm”)
的调用返回null是因为找不到该控件

您可以轻松地将其分解为多个语句来解决问题:

var configUrl = ConfigurationManager.AppSettings.Get("Url");
var mobileFormControl = Page.FindControl("mobileForm")
                            as System.Web.UI.MobileControls.Form;

if(configUrl != null && mobileFormControl != null)
{
    img1.ImageUrl = configUrl.Replace("###", randomString) + mobileControl.Title;
}

这意味着您在其中的某个地方有一个空引用。你能调试应用程序并在调试器到达并进行调查时停止调试器吗?可能
img1
为空,或者
ConfigurationManager.AppSettings.Get(“Url”)
返回空。

是的,我看到
为空
,但它以前工作正常。。您将如何处理“为空”