none
build throws an error "Object reference not set to an instance of an object" RRS feed

  • Question

  • I'm developing an UWP app. Suddenly VS2017, at build or rebuild, throws an error with no specific line of code, at no specific file

    "Error Object reference not set to an instance of an object."

    Every time I hit build this error is thrown, and unables me to make the build, and run a debug instance.

    Also there is another symptom: all .xaml files, with their associated .cs files. at the .cs file, there is the constructor that calls InitializeComponent() method, all .cs files throws the error that can't find the InitializeComponent() method, (or any property/visual control declared in the xaml file)
    for example for app.xaml. build throws the error : "Error CS1061 'App' does not contain a definition for 'InitializeComponent' and no accessible extension method 'InitializeComponent' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?) "

    but these error of missing InitializeComponent() method, ONLY appears when a class is shown in documents tabs in the IDE. as soon I close the document, error go away. still the first error descripted above "Object reference not set to an instance of an object" still is there, and disallows me to build my project.

    I already tried:

    1) rebuild solution
    2) clean solution
    3) rebuild project
    4) clean project
    5) revert to a previous commit (known to be working)
    6) close and reopen VS
    7) reboot the machine
    8) update VS2017 to a newer version
    9) repair VS2017 with the installer
    10) try on another computer
    11) target project to a different version of win10. (now targeting 1809)
    12) Update VS2017 to VS2019

    13) delete completely the project source files, and clone again from gitlab

    none of those did work.

    what can I do?

    I don't know what else I could try, only thing I think, is to rebuild the project from the ground up, with all classes.

    Saturday, June 15, 2019 1:38 PM

All replies

  • Hi Leandro Alsina,

    Sorry for delay in reply.

    According to your description, it seems that the xaml file could not find specified class file. Please check the class name in the .xaml file. And you could refer the format from the sample below:

    .xaml location: [Project name]/ [folder name]/[file name].xaml

    .xaml.cs location: [Project name]/ [folder name]/[file name].xaml.cs

    the structure in .xaml.cs file:

    public sealed partial class test1 : test
    {
        public test1()
        {
            this.InitializeComponent();
        }
    }

    the code in xaml file:

    <Page
        x:Class="[Project name].[folder name].test1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">

    If there is any update information, please feel free to contact us.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, June 17, 2019 9:54 AM
  • Hi Leandro Alsina,

    Sorry for bothering you.

    Does your issue is solved or not? If not, could you please share the update detail error message? We will discuss with the other UWP engineer about this issue. Then we will try our best to provide a solution as soon as possible.

    If you already found the solution, please share it in here or mark the helpful reply, that will help other community members, we can also close this thread for you, thanks for your understanding.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, June 20, 2019 11:22 AM
  • Hello Dylan, thanks for caring.

    as I see, there is not mismatch of classes names between the XAML and CS files

    below an example of the App.xml and App.xml.cs

    App.xml

    <Application    x:Class="Easycoustics.Transition.App"   

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   

    xmlns:local="using:Easycoustics.Transition"   

    RequestedTheme="Light">



    App.xml.cs:

    namespace Easycoustics.Transition{   

    /// <summary>   

    /// Provides application-specific behavior to supplement the default Application class.   

    /// </summary>   

    sealed partial class App : Application


    The unfortunate problem I have, is the error message "Object reference not set to an instance of an object", it has no Error code, has not associated text file, and line of code. It just appears.


    This is as far I can bring.

    If you wish to check out anything more, please ask, i could deliver the whole project if you wish to.

    Thanks very much!

    Leandro

    Wednesday, June 26, 2019 6:43 PM
  • Hi Leandro Alsina,

    Thank you for feedback.

    After it works last time, are there some changes in the project? It is possible that when classes are referenced to each other, some methods are referenced without being declared, causing it to become null. Please check you code for it and the changes.

    If the issue persists, I appreciate that you could share it with one drive or github.

    Look forward to your reply.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, June 27, 2019 9:58 AM