To solve warning 'is never used' in WPF - wpf

I have declared an event in "Question" class as:
public event SectionAffected OnSectionAffected;
I have not used this event in the entire class.But I have used it in another class as:
Question.OnSectionAffected += new Question.SectionAffected(ResetDependentSection);
I am getting warning as:
The event 'QuestionManager.OnSectionAffected' is never used in Question class.
How to solve this warning?

A warning is just that... a warning. Having warnings is not necessarily a bad thing. However, if you really want to remove it, you can specify that in Visual Studio. If you open the relevant project's property page (by pressing ALT + Enter when the project is focused), turn to the Build tab. Click the RadioButton named Specific warnings and enter the specific error code(s) that you want to supress in a comma separated list. You can find out more from the How to: Suppress Compiler Warnings page on MSDN.
UPDATE >>>
I believe that you are looking for the numerical error code number... for this, you should look in the Output Window of Visual Studio. If you don't already use this window when writing WPF, then I would strongly advise you to do so. However, these codes are not always shown in this window.
As an alternative, you can find descriptions and error codes in the C# Compiler Errors and Code Analysis for Managed Code Warnings pages on MSDN.
UPDATE 2 >>>
After doing a quick search online (which is really what you should have done), I found this page which seems about right: Compiler Warning (level 3) CS0219

Related

Wpf: Warning CS0108: 'MainWindow.Close' hides inherited member 'Window.Close()'. Use the new keyword if hiding was intended

I have Wpf dotnet 7.0 app here. and it runs fine. But it gives me a warnings.
Warning CS0108 'MainWindow.Close' hides inherited member 'Window.Close()'. Use the new keyword if hiding was intended. WpfStockAnalyzerHttpClient
C:\Trials\Ex\AsyncCSharp\src\apps\3040-WpfStockAnalyzerHttpClient\MainWindow.xaml
I am not able to understand why? Can someone tell me how to fix?
I get the same error when I run the app using the following command.
dotnet run --project ./WpfStockAnalyzerHttpClient.csproj
C:\Trials\Ex\AsyncCSharp\src\apps\3040-WpfStockAnalyzerHttpClient\MainWindow.xaml(13,51): warning CS0108: 'MainWindow.Close' hides
inherited member 'Window.Close()'. Use the new keyword if hiding was intended. [C:\Trials\Ex\AsyncCSharp\src\apps\3040-WpfStockAn
alyzerHttpClient\WpfStockAnalyzerHttpClient_ekqqvgub_wpftmp.csproj]
You have given the MenuItem the name "Close". When assigning a name to an element, Designer Studio's code generator creates a field with that name.
You can see the file generated by the code generator if you move the cursor to "InitializeComponent" and press F12. On line 47 (this is the number I have, you may have a shift, but not much) you will see "internal System.Windows.Controls.MenuItem Close;".
That is, in fact, you are trying to create a field with the same name as the "Close ()" method already present in the base type.
The Studio warns you about this overlap.
To fix it, change the name of the element:
<MenuItem x:Name="miClose" FontSize="20" Header="_Close" Click="Close_OnClick"/>
Keep in mind that the warning may not disappear immediately. The studio does not always correctly track changes made by the code generator.
But when you re-open the Solution, this warning will definitely be reset.

QuillJS - remove formatting when pasting into the editor

I previously used https://github.com/quilljs/quill/issues/1184#issuecomment-403657128 to make sure that no one can paste formatted text in the QuillJS editor, because I would like people to only use the few editing buttons that I enabled from QuillJs. Since then, it stopped working for me. My question is:
is this working for everyone else?
if no, do you know of an alternative?
One thing about https://github.com/quilljs/quill/issues/1184#issuecomment-403657128 that may behave different than you may have expected could be the 'silent'.
"APIs causing text to change may also be called with a "silent" source, in which case text-change will not be emitted. This is not recommended as it will likely break the undo stack and other functions that rely on a full record of text changes." [ https://quilljs.com/docs/api/#events ]
So if you expected to get the text-change event get emitted but do not get it, then change these two lines
this.quill.updateContents(delta, 'silent')
this.quill.setSelection(index, length, 'silent')
like this:
this.quill.updateContents(delta, 'user')
this.quill.setSelection(index, length, 'user')
Then the text-change event will get fired.

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.

The tag 'XXX' does not exist in XML namespace 'clr-namespace:YYY'

I have implemented a converter to convert Int32 to String to be able to binding a property to a textBox.
I implement this converter in the namespace MyApp.Converters and it is called Int32ToStringConverter.
Then, in my axml I add the reference to my converter as follow:
<Window x:Class="MusicaDB.Views.PrincipalView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
**xmlns:converter="clr-namesapce:MyApp.Converters, aseembly=MyApp**">
Later, in windows.Resources I have:
<Window.Resources>
<**converter:Int32ToStringConverter** x:Key="Int32ToStringConverter" />
</Window.Resources>
I get the error that the tag Int32ToString converter does not exist in the namespace MyApp.Converters,assembly=MyApp.
I have the project in the local hard drive, in the project properties, the destination .NET is framework 4.0, not framework 4.0 client profile and I try to clear the solution and recompile but the problem persists.
Mainly, this is the two solutions that I always find, but don't resolve my problem.
Three fixes to make here:
No spaces -> xmlns:converter="clr-namesapce:MyApp.Converters,aseembly=MyApp"
No misspellings -> xmlns:converter="clr-namespace:MyApp.Converters,assembly=MyApp"
Right delimiters -> xmlns:converter="clr-namespace:MyApp.Converters;assembly=MyApp"
From the the documentation:
Note that the character separating the clr-namespace token from its value is a colon (:) whereas the character separating the assembly token from its value is an equals sign (=). The character to use between these two tokens is a semicolon. Also, do not include any whitespace anywhere in the declaration.
Another possible solution to this problem is that you're not using the same version of .Net in your project and your library.
I am exploring as to why this is happening, but if your converter is in the main assembly, removing the assembly= from your xmlns:converters tag should remove that build error.
For the record ...
I've face a similar problem and if I removed the ";assembly=X" part from the XAML it worked fine
But don't really understand the reason.
As suggested in this blog:
http://zoomicon.wordpress.com/2012/07/02/fix-the-tag-xxx-does-not-exist-in-xml-namespace-clr-namespaceyyy/#comment-7761
I see two possible causes. The first is that you misspelled "assembly" as "aseembly" in the first starred line. Changing the spelling might be enough. The second possibility is that you haven't added MyApp.dll to your project references, which appear like this
in Visual Studio.
All answers are right. And after trying all of them and you cannot configure why its happening, everything seems alright, Please restart the Visual studio.
That worked for me after wasting almost 1 hour. I found everything ok, but restarted the VS with administration.
use the assemble tag only if it is in another project.
other wise use just namespace tag alone.
For me this fixed the issue
In my situation, I had the same problem with xmlns:local="clr-namespace:<mydefaultnamespace>".
I solved this changing the order of the includes. I put it first and all was solved.
A strange behaviour, but this was my workaround that I found in my situation.
In my case, the assembly which contained the namespace was not physically there.
I checked the references of the assembly that had the build error and looked at the properties of the referenced assembly in question.
I navigated to the path and discovered the assembly was indeed missing (which I realised was my own doing), giving rise to the misleading error.
There is one very obscure case when you get this error - if you're using Microsoft.mshtml.dll and you upgrade to Windows 10 anniversary edition, or as it turns out the Creator edition too.
Even if this isn't what happens to you make sure the library containing the component that cannot be found can be fully compiled. Look in the error list (not the grid but the Output console) for any clues.
In my case I was using Microsoft.mshtml.dll as part of an HTML editor and it was unregistered somehow (in the GAC).
The following article explains with screenshots:
https://techninotes.blogspot.com/2016/08/fixing-cannot-find-wrapper-assembly-for.html#comment-form
In short I had to run a Visual Studio command prompt (as admin) run these commands:
cd C:\Windows\assembly\GAC\Microsoft.mshtml\7.0.3300.0__b03f5f7f11d50a3a
regasm Microsoft.mshtml.dll
I did say obscure :-) The important point is to read the errors that may be buried amongst all your warnings because there might be an important clue.
This can be especially confusing if an Operating system update suddenly breaks your project.
I was temporarily replacing a NuGet dll with a local one when this happened. Turned out the assembly was not the same version as the one I was replacing. I built my assembly with the correct version and it worked.

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.

Resources