Xamarin suddenly can't find the static 'Main' method

JonasRembrattJonasRembratt SEUniversity ✭✭✭
edited December 2014 in Xamarin.iOS

I'm currently wrapping up an in-house iOS app when suddenly it wouldn't compile anymore. The compiler errors is:
Program '(my app name)' does not contain a static 'Main' method suitable for an entry point

I have no clue why this happens. Is there some setting somewhere that might have become corrupt?

Answers

  • JonasRembrattJonasRembratt SEUniversity ✭✭✭
    edited December 2014

    The weirdness keeps expanding. Investigating the Main method, this is how Xamarin parses the code (see attached file).
    If I hover the mouse over the highlighted "args" variable (in parameter) the tool tip says 'error CS0103: The name "args" does not exist in the current context'. That error is not generated when I compile, just the measly "Program '(my app name)' does not contain a static 'Main' method suitable for an entry point". Could it be that the compiler fails silently when compiling the 'Program' class with the 'Main' method`? If so, why? it's just the old typical auto generated code that I haven't touched.

    I have tried the usual sorcery, such as cleaning the solution, but Xamarin (or is it XCode?) keeps insisting it can't find a static 'Main' method.

  • JonasRembrattJonasRembratt SEUniversity ✭✭✭
    edited December 2014

    Maybe this is something for a Xamarin employee to check out? I can even send the project.

  • ajaxerajaxer AUMember ✭✭

    May be late to add this but it may helpful to others still.
    I ran into this problem when I accidentally deleted my App.xaml and App.Xaml.cs files.
    Even though I restored the file and re-included them into my project, this error continued to occur.

    The solution was found in the *.csproj file.
    The reference to the App.xaml file has to be thus:

    <ItemGroup>
     <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Page Include="MainPage.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
     </Page>
    </ItemGroup>
    

    If you just include the files in the project then it may add it like this

    <EmbeddedResource Update="App.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    

    which is not sufficient to set the program start point.

  • ajaxerajaxer AUMember ✭✭

    May be late to add this but it may helpful to others still.
    I ran into this problem when I accidentally deleted my App.xaml and App.Xaml.cs files.
    Even though I restored the file and re-included them into my project, this error continued to occur.

    The solution was found in the *.csproj file.
    The reference to the App.xaml file has to be thus:

    <ItemGroup>
     <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Page Include="MainPage.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
     </Page>
    </ItemGroup>
    

    If you just include the files in the project then it may add it like this

    <EmbeddedResource Update="App.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
    

    which is not sufficient to set the program start point.

  • abcr_1abcr_1 Member

    I just had to remove the BuildType -> EXE key from the CSProj file. Visual studio had wrongly added this into the Xamarin Forms project when I added a reference to a .Net Framework Library. No need to add the above mentioned ItemGroup section. Just do a comparison of any working xamarin project with the one causing trouble, you would know.

Sign In or Register to comment.