Xamarin Studio Designer error - Custom iOS Control using MvxView - c#

I've created a custom iOS control using Xamarin Studio and while it works fine at runtime when I open the xib which has the control dropped onto it the interface builder displayed it with a nasty error (below).
The project uses MvvmCross and the backing class for the xib inherits from MvxView - and herein lies the problem. If I change this to a standard UIView the control is displayed just fine - but I lose the binding capabilities I need.
Now - I'm not expecting the designer to display a nicely rendered interpretation of my control, I know that won't happen.
What I want to know is whether this error is a byproduct of using MvxView and I just need to live with it or whether I've missed something in my implementation - I'm guessing I've not overridden something but can't work out what it is.
[Edit: 18 Nov 2016]
Digging through the MvvmCross code on Github I've located the cause of the problem - but I'm no closer to fixing it.
Basically the backing class for my control has the standard constructor (this is the line referenced in the error that I've partially blurred):
public ResidentHeaderView(IntPtr handle) : base (handle)
{
}
Following the stacktrace up from there it turns out that the code is trying to resolve a BindingContext and failing - because I am in designtime here.
If I comment out the constructor and rebuild then the error in the designer disappears - and of course the app will crash when I access a page that contains this control because the contructor is required.
So I know why it's happening (and that it's nothing serious in my code) but I don't know how I can resolve it.
Any further input greatly appreciated.
Thanks in advance

Related

VS crashes and winforms data lost

I am developing an application using Visual Studio 2019 and I am designing winforms.
Visual Studio commonly crashes when I am creating the forms by freezing, and recently my designed winform has somehow disappeared (even though I saved it). When i open it it shows as the default winform that is shown when a new one is created:
When I browse the solution explorer it seems that I can still see all the components I had added to the form:
Finally, when I try to restart and manually add the components back, I get an error message saying that the component can't be added due to duplication - which is probably because they are somehow still there (as shown in the solution explorer) but the data has been corrupted somehow:
If anybody has any idea of how to recover the data and the winform, I would very much appreciate it. If any additional information is required, please let me know. Thanks!
According to your description, first, the controls actually exist, but they are not
displayed in the design window.
You can try to check whether the. add statement of each control added to the window still
exists in the .Design.cs file.
If not, you can add it manually.
Second, solution explorer shows the missing components, but there is an error in adding
components. It means that only the declaration of this control in the .Design.cs file does
not assign a value to this control. You can delete the declaration of the component in the
.Design.cs file, and then add the component in the design interface.
Result:

Binding using Source and x:Reference leads to design-time error

for our WPF application I have designed a CustomControl to mimic some flyout-like behavior. The flyout basically just consists of a FrameworkElement which holds the content that is placed inside the flyout.
Controls that are placed in the FrameworkElement of the flyout are, of course, bound to other controls. However, I am confused as this results in several problems:
I can not use ElementName=sourceName to set the source of the binding. Instead I have to use Source={x:Reference sourceName} to denote the source.
The XAML editor of VisualStudio marks all lines where a binding of this type occurs and the ErrorList shows "Object reference not set to an instance of an object" for each occurrence of the binding (no exception is thrown within the designer view).
The project builds successfully and during runtime all bindings work flawlessly! Besides that, it does not matter if the flyout is implemented as a UserControl or a CustomControl.
If a control that is not placed in the flyout is bound to the same source I can use ElementName=sourceName without any problems and the correct values are displayed in the designer.
As proposed in some other replies concerning this error I tried to attach the VS instance to the debugger of a second instance of VS but no errors/exceptions are displayed there.
As already mentioned, everything works at runtime. However, as multiple developers are working on this project it is not acceptable to have any errors at all; warnings would be acceptable to a certain extend.
We know that using a binding proxy (like it is proposed in e.g. https://stackoverflow.com/a/22531679/119177) should/could solve the problem. However, because the current binding is actually working, we hope to solve the design-time problem some other way (maybe even with just suppressing the error message).
Thanks for your help!

Windows Forms designer and custom CodeDomSerializer

I am currently putting together a prototype for a custom tab control we are trying to implement in c# for .Net 2.0. As the control itself works fine, we are now trying to integrate full design-time behaviour. This does include a custom CodeDomSerializer at a certain point to tell that the tabs have to be added as well. This does work fine now (after a longer process of trial and error).
But there is a problem left that seems to have to do with Deserialization. The designer code is created just fine and the designer looks just the same. But when I hit rebuild project, the forms designer sometimes show this error:
The variable 'piTabControl1' is either undeclared or was never assigned
http://msdn.microsoft.com/en-us/library/4008y84t(v=vs.80).aspx
The error does not appear every time, but it always happens when I have just added a new tab. The error points to this line:
this.Controls.Add(this.piTabControl1);
But I know that the variable is assigned, as this is in the code a few lines before:
this.piTabControl1 = new pdfforge.PdfCreator.Controls.PiTabControl();
The application also does compile and run with everything shown properly. If I close the Designer and reopen it, it is also shown without that error. So I suspect that there is something going wrong when Deserializing the code or updating the designer.
I have uploaded the full solution here, because it is just too much code to paste here:
http://www.chinery.de/dateien/TabControlTest.zip
To reproduce this in the project, you will first have to recompile the whole solution for the custom controls to be compiled. Then you can open Form1 and hit rebuild. If it does not produce the error, you can try adding or deleting tabs from the tab control.
I really don't have a clue how to approach this, because I can't tell the inner state of the Forms designer. I am very thankful for any hint. I can also add specific code snippets here if requested.

Form Designer unable to find type

In a windows form I am populating a combo box with the following code.
this.JackStudTypeComboBox.Items.AddRange(ViewController.GetJackStudMaterialType().ToArray());
When I attempt to open the Form Designer I get the message that the ViewController type is not found.
The ViewController class is located in the same project as the form. Compiling the project has no issues, and running the project results in the expected behaviour.
So, how do I convince the Form Designer to locate this particular class, or to ignore the fact that it is unable to find it or do anything useful with it when in static design mode?
Don't do that.
You should never put any custom logic in InitializeComponent().
Move that to the constructor and everything will work fine.

Visual Studio isn't generating code to instantiate instance of custom control

I've created a custom control using C#, .Net3.5, and Visual Studio 2008.
I'm then adding that control to another control by dragging it from the toolbox.
After doing this when I try to compile I get an error as follows:
Error 1 Warning as Error: Field 'MyNamespace.MyControl._myCustomControl' is never assigned to, and will always have its default value null
Looking at the Designer.cs file this is due to the fact that VS never generates the following code:
this._rgReportGallery = new MyNameSpace.MyCustomControl();
The field itself is there, and the code to add it to the control I'm putting it in, just the instantiation code is missing.
I can add that code manually and everything seems to work, but as soon as the designer.cs file is regenerated it goes missing again.
I've even successfully added a different custom control and had that code get generated.
Does anybody know what could be causing this?
I was having this issue and a reply here helped me find the issue, I was using the "internal" keyword for both my component accessibility and the constructor accessibility. As Brent mentions in a couple posts above mine, VS designer apparently has issues generating an instantiation line with anything except a public constructor, so never make a custom user control where the class accessibility and constructor(s) are anything but "public."
By the way, this occurred for me on Visual Studio 2005, and it doesn't surprise me that it also would happen on Visual Studio 2008. It likely happens on earlier versions of VS as well.
Have you adjusted the constructor of the custom control in any way? The default constructor for controls is a parameterless one, and I know I've had trouble in the past when creating a constructor for my controls that requires parameters. In those cases I always provide two constructors. That way the parameterless one remains for the design mode in VS.
Also make sure your UserControl's constructors are public. I've had issues with internal UserControls and the VS2008 SP1 WinForms designer code generation. It failed to generate the allocation line like you mentioned.
Even though the .Designer.cs files look like simple code, playing around in that code is very risky because it can easily break the Windows Forms Designer. I've heard a lot of people just abandoning the WinForms designer because they say it does not work. It's indeed easy to break, but if you don't try to play in the .Designer.cs file, it works like a charm.
If you have edited the Designer.cs file manually, it might explain why it keeps rewriting itself wrong. It's hard to know how to fix it though. If your UI is not too hard to redo, I would just redo it (whatever is in your main .cs file will be untouched). Otherwise you can look at a similar form to see a model of how exactly it should be formatted (the order of the statements is important).
Do you have the latest service pack for Visual Studio 2008? This usually happens when you don't have the latest service pack.

Categories