Error when adding user-defined control to a form. - winforms

I have an user-defined control which includes a property ElementList of IList<WFParament> type. When I add my control into a form, I get the error:
"WorkFlowDesign.WFParament[]" can't be transfered into "WorkFlowDesign.WFParament[]"

Does your usercontrol do anything on load? If so, try wrapping it in:
if(!DesignMode)
{
//Do something
}

I would verify that you don't have two versions of the assembly containing the type WorkFowDesign.WFParament loaded/referenced. This could happen if your project where you are using the user control references one version of the assembly while the user defined control is compiled against a different version. If this is the case you will need to update one of the two so that they are referencing the same version of the assembly containing WorkflowDesign.WFParament.

Related

how to get rid of namespace errors caused by including custom control in wpf application?

I am working on a wpf-project that used a ScrollViewer to show a range of items.
In order to create a more advanced look and feel for the application, I replaced the Scrollviewer with a Carousel-control.
The code for the Carousel-control I downloaded from here:
https://www.codeproject.com/Articles/181835/WPF-Carousel-Control
Conceptually, the carousel control (as part of my wider application) consists of a large black box (which one does not need to touch) plus just a few lines of code for plugging in the carousel control. The black box is the Carousel project, highlighted in the following screenshot:
In order to plug the carousel-control in the application, just a couple of lines had to be commented out and a couple of other lines had to be added. The comments in the following two screenshots mark off the lines of code that had to be commented out and the lines of code that had to be added (in order for the scrollviewer-control to be replaced by the carousel-control):
... and (at the end of the file):
Furthermore, at the beginning of the xaml-file that contains the carousel, the following line was included:
xmlns:Carousel="clr-namespace:Carousel;assembly=Carousel"
as can be seen in the following screenshot:
As you can see, at the moment, the code for the scrollviewer is commented out. Hence, the application is using the Carousel at the moment.
This carousel works fine. However, the error list shows a bunch of errors, mostly of the following type:
the name "XYZ" does not exist in the namespace "bla".
The following screenshot shows some of the error messages:
As already mentioned, the carousel-control works despite those error messages. However, I still need to get rid of the error messages before leaving this project.
Regarding the error messages, the following points might be of interest:
No error messages are shown, when the scrollviewer-control is used.
As you can see from screenshot 5, most error messages refer to line 1 of the file CarouselControl.xaml. This file is located inside the "black box":
The beginning of file CarouselControl.xaml contains the following lines of code:
As you can see from screenshot 5, most of the error messages say that some name or property does not exist in namespace xyz, whereby namespace xyz is one of the namespaces listed at the beginning of file CarouselControl.xaml (see screenshot 7).
********************************UPDATE*****************************************
(Right-click on) Solution -> Properties -> Configuration Properties, I noticed that it was apparently not possible to change the configuration of the Carousel-project to anything other than platform x86:
No matter which platform I selected (from the drop down menu at the top of the screenshot), the platform for the Carousel-project stubbornly remained at value "x86".
Might this have something to do with the error messages?
I'm not sure how useful this may be, but I believe I have found the code that was the source of my problem:
var variables = values[0] as ObservableCollection<variable>;
var identifier = values[1] as string;
var variable = variables.SingleOrDefault(x => x.identifier == identifier);
if (variable == null) return "";
This is code of my converter to access a variable in a collection and return its value as a string, it was used on a TextBox control.
Looking back over my branches, it seems that I made this change:
var variable = variables?.SingleOrDefault(x => x.identifier == identifier);
Resharper suggested adding a Null-conditional Operator at this point, which solved my issue. It would seem that the designer was returning errors due to the LINQ expression, since the collection at this point was uninitialized.
I would look through your code to see if you have a similar instance of uninitialized collections.

WPF Drag, drop image into canvas, reject wrong ones

I have 8 images and 2 canvas, and i am trying to do a drag drop game, which will be able to reject the wrong image that is drop into the wrong canvas. I tried many codes online just for the drag drop function but it didn't work. The most common error I have is
1) "The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'"
2) 'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
How do solve the problem? Thankyou in advance
These are very basic errors and developers typically solve these by pasting them into any search engine and reading the result pages. If you can't fix these kinds of problems yourself, you'll have real problems later. Either way, your first error is this:
The type 'WpfApplication9.Window1' already contains a definition for 'butterfly'
In plain English, this means that you have a class named Window1 in a namespace named 'WpfApplication9 (so I'm assuming this is your 9th test application) and in that class, you have declared a property, method, enum, or other member named butterfly... the actual problem is that you have defined two members named butterfly in the same class. You cannot do this, so rename one of them.
Your second error is:
'WpfApplication9.Window1' does not contain a definition for 'Grid_PreviewMouseDown' and no extension method 'Grid_PreviewMouseDown' accepting a first argument of type 'WpfApplication9.Window1' could be found (are you missing a using directive or an assembly reference?)
Again, this is a very common error and simply means that you have attached a PreviewMouseDown event handler to your Grid, but then you didn't actually declare the handler method itself. The solution is to implement your Grid_PreviewMouseDown method.

Is it possible to create inherited SqlDataTable in SqlDataSet. Devart dotconnect

The problem is that when I redeclare standard SqlDataTable to my CustomSqlDataTable inside SqlDataSet. It works until you change the SqlDataSet that contain your custrom dataTable. After any change in SqlDataset it recreate code of own definition and all dataTables again becomes standard SqlDataTable. How to avoid it?
Thanks!
The MyTalbeDataTable class (inherits Devart.Data.SqlServer.SqlDataTable), which is a part of a Devart typed DataSet, is generated with a "partial" keyword. Therefore, you can create a separate MyClass.cs file and extend a "predefined" functionality of MyTalbeDataTable. The code within MyClass.cs will not be wiped out because this is a custom file.

Warnings and errors (CS0436, CS0234) when creating user controls composed of other user controls in the same project

I'm working on a Windows Forms solution with many winform ui projects.
There is a class library project that contains some custom shared controls, named MyControls.
Now, when I create a control in MyControls
that is composed of one or more controls in the same project, I run into problems.
I either get compilation warnings: warning CS0436: The type 'MyType' in 'path-to\MyType.cs' conflicts with the imported type 'MyType' in 'MyControls.dll'. Using the type defined in 'path-to\MyType.cs'. Or I get a bunch of different compilation errors, all pointing to "MyControls.dll" (error CS0234 - "are you missing an assembly reference?").
I get either the errors, or the warnings, never both.
How to solve this?
Note
I added visual-studio-2010 because that's the version I experienced the problems with. No idea if this relates to other versions too.
I found that Visual Studio adds a self-reference to MyControls when I drop a control from the MyControls project on another control in MyControls:
<Reference Include="MyControls, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" />
My current work-around is to manually delete this reference from the MyControls.csproj using a text editor.
When I've done this, everything works fine, until I drop another control that triggers a self reference.
Better solutions are appreciated!
you can make a small and "legal" change in your solution and get the "legal" solution... lets say your project name is: "project01"
go to references folder in your project - one of your references called "project01" - just remove it...
the the warning is very fair! you design a form and in the other hand import your project as a reference!
I know this thread is a bit old, but I just went looking for a solution to this issue, and it seems that MS doesn't have anything other than what Marijn suggested earlier:
https://connect.microsoft.com/VisualStudio/feedback/details/613502/automatically-add-self-reference
Hopefully it's fixed in VS 2012.

How do you reference a field in the Embedded Code of an SSRS report

Is there a proper way to reference the fields of a ssrs report from the embedded code of an ssrs report?
When I try to use Fields!Program.Value I get the following error --
There is an error on line 3 of custom code: [BC30469]
Reference to a non-shared member requires an object reference.
Upon googling I found you could reference the Parameters of a report by prepending Report. at the beginning. So I tried this Report.Fields.Program.Value.
That results in the following error...
There is an error on line 3 of custom code: [BC30456] 'Fields' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode'.
So... in summary, is there a way to reference the fields from the embedded code. I figured out I could pass the field vals to the function itself but I would prefer to reference the fields directly.
Seth
You have to pass it in as a parameter.
=Code.ToUSD(Fields!StandardCost.Value)
You do have two other alternatives to passing by parameter, though neither is very pretty.
(Beware! After I wrote the following paragraph I discovered defaults from queries are not supported in local processing mode so this first solution may not be viable for you as it was not for me.)
You can create a hidden report parameter with a default value set from a dataset, then reference this with the Report.Parameters!MyParam.Value syntax. You have to be careful when testing this, as (at least in BI studio 2005) the report parameters don't seem to get reliably re-initialised from the DB in the Preview tab.
Alternatively you can create a hidden textbox on the report with its text set from a dataset, and then reference the textbox from code. In this case you have to pass the ReportItems object as a parameter, but the slight advantage is that it is only ever one extra parameter. Be sure to strongly type the parameter when declaring it:
public Sub MyCustomCode(ri as ReportItems)
The code will work in BI studio without the type declaration but for me it caused errors with the report viewer control in local processing mode if 'as ReportItems' was not present.
In either case, this is only really useful for page level data, so functions for use in a table should still take parameters.

Resources