Default Constructor not found for type System.Data.DataColumn

Bob_ReckBob_Reck USMember ✭✭✭

Folks, need your help.

I have an error that has started since I've made my latest updates. The updates don't have anything to do with the UIViewControllers the error is happening on. The error is "Default Constructor not found for type System.Data.DataColumn." This happens on a screen where I am trying to fill a UITableView from my SQLLite database. I am using the SQLLite component from the component store.

I've done a bunch of searching and I saw a lot of talk about turning off linking. So when I set "Don't Link" on my app, it builds and becomes too large for the app store.

This problem does not happen in debug mode. It only happens when I submit it to the app store.

Any ideas?

Posts

  • adamkempadamkemp USInsider, Developer Group Leader mod

    This document may help. You can use a special XML file to tell the linker about specific things you don't want stripped. That will let you preserve the things that are getting stripped that you can't access directly to tag with the Preserve attribute.

  • Bob_ReckBob_Reck USMember ✭✭✭

    @adamkemp, thank you for the info. Unfortunately...

    I guess I'm an idiot because I don't understand this problem. I'm so f*&king frustrated right now. This has stopped me from updating my app for MONTHS now. And it all started with a Xamarin upgrade. No code changed and simply recompiling my app back in December caused this problem to start.

    I am using SQLIte as a database in my app. In my views, I am executing lines like the following where the error is occurring...

    SQLiteConnection db = new SQLiteConnection("MyDatabase.db",false);
    var results = db.Query

    ("SELECT * FROM Table"); <--- Error happens here. Error, as stated above, is Default Constructor not found for type System.Data.DataColumn. I have no clue where I'd put a constructor for System.Data.DataColumn. Nor do I understand where I should put the preserve tag (like mentioned in the article @adamkemp suggested). Please someone help me with this so I can push out a build. Thank you very much!
  • adamkempadamkemp USInsider, Developer Group Leader mod

    The problem is that some code is getting stripped out because the build system can't tell that it's used. This document explains what the linker is and what it does. The document I linked to above explains how to tell the linker not to strip out certain types that you know are used. To fix this problem you would use the steps listed in that document to tell the linker not to strip "System.Data.DataColumn".

    Another approach would be to add a line of code somewhere in your app that does this:

    var t = typeof(System.Data.DataColumn);
    

    That should also convince the linker that this type is needed and prevent it from being stripped out.

  • Bob_ReckBob_Reck USMember ✭✭✭

    @adamkemp you are my hero!

    Ok, so adding the "var t = typeof(System.Data.DataColumn);" did not work. But the additional documentation on the linker did. Thank you for that. What worked for me was adding "--linkskip:System.Data" to the mtouch arguments worked.

    I now understand a lot more about the linker and what it does. Thank you very much.

    Bob

  • jtthjtth Member ✭✭

    @adamkemp How to do this for custom classes? ex:
    public class CustomCells : ViewCell { public CustomCells() {} }

    Results in Default Constructor not found for type CustomCells

    Why is that? Attempted using the '--linkskip' solution to no avail (assume this is due to the code not being an assembly rather a programmer defined class) . Please advise.

  • adamkempadamkemp USInsider, Developer Group Leader mod
    I don’t have enough context to know what’s going wrong with your code, and I’m pretty out of touch with Xamarin stuff today. I suggest you make a new question post and include more detail so someone else can help you out.
  • jtthjtth Member ✭✭
    edited March 2018

    @adamkemp Basic generic page, class, and ViewCell extension. Page has a listView which uses the custom class as the itemSource and the ViewCell class as the itemTemplate. This set-up used to work without a hitch. No changes made (to my recollection) and out of the blue, VS started generating,

    System.MissingMethodException: Default constructor not found for type CustomCells

    As one can see, CustomCells contains a constructor.

    Full example:

    using System;
    using System.Collections.ObjectModel;
    using Xamarin.Forms;
    
    namespace MyApp
    {
        public class MyPage : ContentPage
        {
            // Variables
            public ObservableCollection<CustomClass> listViewSource { get; set; }
    
            public MyPage()
            {
                // Create listView
                ListView myListView = new ListView
                {
                    RowHeight = 40,
                    SeparatorVisibility = SeparatorVisibility.None,
                    ItemTemplate = new DataTemplate(typeof(CustomCells)),
                    ItemsSource = listViewSource,
                };
    
                // Prevent highlight via selection
                myListView.ItemSelected += (sender, e) =>
                {
                    ((ListView)sender).SelectedItem = null;
                };
    
                // Page layout
                var ListViewLayout = new StackLayout
                {
                    Padding = new Thickness(0, 20, 0, 0),
                };
    
                // Add children to layout
                ListViewLayout.Children.Add(myListView);
    
                // Assign content
                Content = ListViewLayout;
            }
        }
    
    
        public class CustomCells : ViewCell
        {
            public CustomCells()
            {
                //
                // Instantiate views
                //
                var labelVar = new Label
                {
                    LineBreakMode = LineBreakMode.NoWrap,
                    HorizontalOptions = LayoutOptions.Center,
                    VerticalOptions = LayoutOptions.Center,
                    TextColor = Color.White,
                    FontSize = 10,
                    WidthRequest = 40,
                };
    
                //
                //  Set bindings
                //
                labelVar.SetBinding(Label.TextProperty, new Binding("LabelNumber"));
    
                //
                //  Instantiate layouts
                //
                var horizontalLayout = new StackLayout()
                {
                    BackgroundColor = Color.Black,
                    Orientation = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.Fill,
                    VerticalOptions = LayoutOptions.Center,
                };
    
                //
                //  Add views to the view hierarchy
                //
                horizontalLayout.Children.Add(labelVar);
    
                //
                //  Create swipe gesture actions
                //
                var moreAction = new MenuItem { Text = "More" };
                moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
                moreAction.Clicked += async (sender, e) =>
                {
                    var mi = ((MenuItem)sender);
                    Console.WriteLine("More Context Action clicked: " + mi.CommandParameter);
                };
    
                //
                //  Add to the ViewCell's ContextActions property
                //
                ContextActions.Add(moreAction);
    
                //
                //  Add to parent view
                //
                View = horizontalLayout;
            }
        }
    
        public class CustomClass : BaseViewModel
        {
            public int LabelNumber { get; set; }
        }
    }
    
  • adamkempadamkemp USInsider, Developer Group Leader mod
    As I said, I’m too out of touch to help you. I suggest you make a new post for better visibility. Generally a zip file with a complete building test project works best.
Sign In or Register to comment.