Bug 52418 - Cannot use form previewer on VS 2017 RC
Summary: Cannot use form previewer on VS 2017 RC
Status: RESOLVED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Xamarin.Forms Previewer ()
Version: 4.3.0 (C9)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-02-09 12:04 UTC by Thomas Bienkowski
Modified: 2017-04-05 23:34 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Xamarin logs (268.49 KB, application/x-zip-compressed)
2017-02-09 12:04 UTC, Thomas Bienkowski
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Thomas Bienkowski 2017-02-09 12:04:00 UTC
Created attachment 19772 [details]
Xamarin logs

I have been trying to get the XAML previewer to work on my machine, however, it will not render any object, claiming that it can't find the parameterless constructor for my object ( a generic page ).
The exact error message is "This control does not have a default parameterless constructor. It cannot be previewed unless it contains one."
Comment 1 Alan McGovern 2017-02-09 12:20:54 UTC
Can you attach a sample that reproduces the problem?
Comment 2 Thomas Bienkowski 2017-02-09 12:34:50 UTC
This causes the issue:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Learn.MVVM.View.Page1">
    <Label Text="Hello, XAML!"
         VerticalOptions="Start"
         HorizontalTextAlignment="Center"
         Rotation="-15"
         IsVisible="true"
         FontSize="Large"
         FontAttributes="Bold"
         TextColor="Aqua" />
</ContentPage>
Comment 3 Alan McGovern 2017-02-09 17:36:55 UTC
We'd need the implementation of the `Learn.MVVM.View.Page1` class, in a compilable project, to fully diagnose/resolve the issue.
Comment 4 Tony 2017-02-18 12:20:12 UTC
I'm having the same issue. At some point (I guess after one of the Xamarin Studio updates) XAML Preview just stopped working in all my views with the same error message (although there is definitely default parameterless constructor present in them). It doesn't even work if I create a fresh empty ContentPage in my project.

Unfortunately, I can't reproduce this in a standalone manner. It works fine if I create a new solution and try to mimic my view class structure and project settings.
Comment 5 Tony 2017-02-18 12:28:11 UTC
Forgot to mention: I use Xamarin Studio on Mac, not Visual Studio on Windows. But the error message is exactly the same.
Comment 6 Alan McGovern 2017-02-19 14:36:46 UTC
If you can provide a sample project (or if you wish to privately share your actual project with us) we should be able to diagnose the issue.

Alternatively if you can provide the log files from a session where a xaml file failed to render we may be able to figure out the underlying issue from that.
Comment 7 Tony 2017-02-19 16:36:53 UTC
Hi Alan.

How can I share my project privately?
Comment 8 Alan McGovern 2017-02-22 17:04:05 UTC
We have a few options:
1) If you have a preferred way of hosting a zip of the project (dropbox etc) you could put it there and email us a link to it. We will let you know when we've downloaded it so you can remove it.
2) You can email it directly to me (same email address as I use in bugzilla) and I'll review the issue.
3) We can create a new private bug which you can upload the files to.

Option 1 leaves you in control of the availability of your data, which some people prefer. Option 2 also works well for small projects.
Comment 9 FernandoVM 2017-03-10 17:11:16 UTC
Dear Alan, I had this same issue when I upgraded my environment (versions bellow) and after a not so easy creativity exercise (because xamarin logs should help more, but it just show a inespecific XamarinFormsDefaultConstructorNotFoundException whithout indicates the target type of the exception) I discovery that my problem was generated by my App class (in the portable library). 

Then, I simply added the parameterless constructor (to be used only by previewer):

        public App() 
        {
            this.InitializeComponent();
        }

It's important invoke the InitializeComponent method in parameterless constructor, otherwise we will get errors of static resources not found (if x:StaticResource is used).

Xamarin   4.3.0.784 (73f58d6)
Xamarin.Android   7.1.0.41 (9578cdc)
Xamarin.iOS   10.4.0.123 (35d1ccd)

It's all, I hope I have helped!


[]'s
FernandoVM
Comment 10 Alan McGovern 2017-04-05 16:13:12 UTC
That's definitely useful information. We've already improved this error message so it includes the actual type of the object, and will indicate that you need to call `InitializeComponent` too. This should ship as part of a future update. Thanks for the report!
Comment 11 FernandoVM 2017-04-05 23:34:11 UTC
You are welcome!

Great news, the xamarin is an amazing tool and improve the error messages is very important to help us to deal with this type of problems.

Best regards,
FernandoVM