在開發Azure Sphere應用時,如果出現項目無法編譯,出現“Object reference not set to an instance of an object”時,必須從下面兩個方面進行檢查。
1. 檢查Visual Studio 2017安裝時,是否安裝了Desktop Development with C++組件,另外,是否選中了"Visual C++ tools for CMake and Linux" 和 "Embedded and IoT Development"這兩個項目,如下圖所示。
2. 安裝完成以后,去https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ClearMEFComponentCache這里下載Visual Studio的MEF組件清理插件並安裝。安裝完成以后,在Visual Studio 2017的Tools-Clear MEF Component cache菜單中清除Cache。
3.之后,用Visual Studio打開Azure Sphere的工程,點擊Build-Rebuild Solution,就可以重新編譯項目了。