{"id":1364,"date":"2013-02-11T21:36:07","date_gmt":"2013-02-11T20:36:07","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=1364"},"modified":"2013-05-03T17:58:45","modified_gmt":"2013-05-03T16:58:45","slug":"infopath-object-reference-not-setinstance","status":"publish","type":"post","link":"https:\/\/www.stuartroberts.net\/index.php\/2013\/02\/11\/infopath-object-reference-not-setinstance\/","title":{"rendered":"InfoPath Object Reference not set Error"},"content":{"rendered":"<p>After designing an InfoPath form and as you try to upload and register the form to SharePoint, through the Central Administration site for example, you may see the following error:<\/p>\n<p><em>Object reference not set to an instance of an object<\/em><\/p>\n<p>You may also see the following error when previewing the form within InfoPath Designer:<\/p>\n<p><em>InfoPath cannot open the selected form. There was an error while loading the XML Schema for the form.<\/em><\/p>\n<p><!--more--><\/p>\n<p>Examining the ULS log while uploading the form, some additional information is obtained, none of which really sheds much light on the cause of the problem.  We have:<\/p>\n<p><em>ConstructFromXsnFile failed with unhandled exception System.NullReferenceException: Object reference not set to an instance of an object.<\/em><\/p>\n<p><em>LoadDocumentAndPlayEventLog failed with unhandled exception System.NullReferenceException: Object reference not set to an instance of an object.<\/em><\/p>\n<p>and<\/p>\n<p><em>System.NullReferenceException: Object reference not set to an instance of an object.<\/em><\/p>\n<p>All of which pretty much do little more than confirm the original error.<\/p>\n<p>For all three errors above, there is one common exception reported, at least for the error I encountered:<\/p>\n<p><em>Microsoft.Office.InfoPath.Server.SolutionLifetime.Filters.<br \/>\nFindElementInExpressionByBindingName(BaseControl targetControl, String name)<\/em><\/p>\n<p>The form I was designing had some filters defined against data sources bound to a drop down list control.  So, first thing to try was to remove the filter, which resulted in the form successfully previewing and deploying to SharePoint.<\/p>\n<p>OK, so why was the filter causing the error?  I&#8217;ve used filters countless times in the past without seeing this error.<\/p>\n<p>Moving the drop down list (with filter) to another view was also successful.  So it can&#8217;t be the filter causing the error, even if that is what it originally looked like.<\/p>\n<p>So, back to the view where the error occurs.  Looking at it again, I noticed I had some text contained within an unbound field, which was used on most of the views, but not the one I successfully got working with the drop down list in my previous test.  So, I tried creating a source for the text box and bound it to the unbound control.  In doing this the form correctly previewed and was able to deploy without error.<\/p>\n<p>For a reason I can&#8217;t explain fully, having unbound controls declared on your form while setting filters on data sources causes the <em>Object reference not set to an instance of an object<\/em> error to occur.<\/p>\n<p>The moral or this story is to not have unbound controls in your form.  In my case, I removed the text which was displayed in an unbound control (and used in most views) and replaced it with a simple one cell table  with content formatted how I wanted it and then copied it over all occurrences of the pesky unbound control.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After designing an InfoPath form and as you try to upload and register the form to SharePoint, through the Central Administration site for example, you may see the following error: Object reference not set to an instance of an object &hellip; <a href=\"https:\/\/www.stuartroberts.net\/index.php\/2013\/02\/11\/infopath-object-reference-not-setinstance\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[9],"tags":[84],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-m0","_links":{"self":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1364"}],"collection":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=1364"}],"version-history":[{"count":8,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1364\/revisions"}],"predecessor-version":[{"id":1467,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/1364\/revisions\/1467"}],"wp:attachment":[{"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=1364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=1364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=1364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}