InitializeComponent() - Ambiguous invocation warning? - c#

I admit that I'm new to the world of xaml but seeing warnings using the built-in Visual Studio templates indicate that there might be another issue besides my brain.
If I create an empty VSIX Project (it has to be a VSIX Project) in Visual Studio using Add -> New Project, and then proceed to create a new user control using Add -> New Item -> User Control (WPF), after I have compiled the code, the editor shows me the warning Ambiguous invocation on the line InitializeComponent(), as shown below:
EDIT
There are warnings in the Designer view as well, shown below:
The warning is only present in the editor. Building the project is no problem, as shown below:
Please note that there are NO warnings if you add a User Control (WPF) to a Class Library (.NET Framework) project, as shown below:
If I look in the obj/Debug/ folder of SomeProject I see two files for SomeControl. The first is SomeControl.g.cs, and the second is SomeControl.g.i.cs. The files are identical.
The same goes for the obj/Debug/ folder of SomeOtherProject, without the warning.
I have cloned various official Microsoft repos (e.g. UnitTestBoilerplateGenerator) and the warning is present here as well, for example in: src/View/CreateUnitTestBoilerplateDialog.xaml.cs at InitializeComponent(), as shown below:
What's going on?? =(
EDIT
This is using Visual Studio 15.4 and ReSharper 2017.2.2; I don't seem to be getting this warning with older versions of Visual Studio/ReSharper.
EDIT
This seem to be a ReSharper specific problem, since after suspending ReSharper the warnings are no longer present. I have submitted a bug through ReSharper -> Help -> Report a Bug or Submit Feedback....

It is a known issue for ReSharper 2017.2.x
Update: It was fixed in ReSharper 2017.3 version.

Related

Suppress Blazor css ::deep warning

In a css file of an asp.net Blazor app when I use ::deep VS emits a warning "Validation (CSS 4.0): "::deep" is not a valid pseudo-element." That might be true for regular CSS, but not in the context of a Blazor app.
Is there a way to suppress it? Right-click -> Suppress -> In File / In Source do nothing.
You can add deep to the vendor specific extensions.
I've added it to the Microsoft extension and it works.
Open with an editor (in Administrator mode) the file:
C:\Program Files (x86)\Microsoft Visual Studio\2019\<your version>\Common7\IDE\Extensions\Microsoft\Web Tools\Languages\Schemas\CSS\1033\css-vendor-ms.xml
Go to line ~69 and add the following code:
<CssPseudo name="::deep"
_locID="ms-browse-pseudo-element"
_locAttrData="description"
version="3.0"
browsers="IE11"
description="Blazor child component support."
standard-reference="https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-5.0"/>
Restart Visual Studio.
Now I can see the source code as:
For Resharper users, editing the css-vendor-ms.xml is needed but does not completely solve the issue. Resharper will continue to highlight ::deep elements as errors in your solution. This is currently a known bug, which will hopefully be resolved in a future build.
As a work around, go to Resharper Options --> Code Inspection --> Inspection Severity --> CSS --> Potential Code Quality Issues --> Unknown CSS symbol and drop the severity to Warning (or lower).
This has now been fixed as of the latest preview version of Visual Studio 2022:
https://developercommunity.visualstudio.com/t/Support-::deep-in-razorcss-CSS-isolati/1623976
I just downloaded 17.3 and my project is now down to zero warnings again! Look forward to it being released properly.

Whats the difference between the 'Code Refactoring' and the 'Analyzer with Code Fix' template

I thought I'd delve into writing a custom code analyzer, so that I can enforce a rule and and allow code fixes to be applied.
Upon opening VS after installing the required workload I see the following available templates:
Code Refactoring
Analyzer with Code Fix
Standalone Code analysis Tool
What are the differences? How would i know what to pick?
The "Code Refactoring" template gives you a VSIX extension with a separate project for the refactorings. The extension shows a new entry in the "Quick Actions" menu when the cursor is on matching code. This way, you can provide a quick code fix without having to define an additional analyzer ID and showing the user an entry in the error list.
The "Analyzer with Code Fix" template gives you a VSIX extension and a separate project for the analyzer which can also be deployed via NuGet. The analyzer can be used to show a squiggly line below matching code, showing an entry in the error list, which can be configured to be a message, warning or even an error - providing a code fix is optional.
The "Standalone Code Analysis Tool" template gives you a console project, that will open a solution workspace. This way, you can analyze your projects without having to install any VSIX extensions or NuGet packages to the project or the IDE - it is supposed to be called from a command line, which makes most sense when used on a build server. The template does not include any analyzers or refactorings.

How to show all Suggestions/Warnings/Errors in the Error List windows of Visual Studio 2019

The problem is that not all visual studio suggestions, warnings and/or errors are shown on solution build.
Let's say that on solution build, a total of 22 warnings are shown. After solution build, upon opening .cs files within projects, more warnings are being shown.
Steps:
Rebuild solution
Error List shows 0 Errors, 22 Warnings, 0 Suggestions
Open a .cs file from within a .csproj
Error List shows 0 Errors, 22+ Warnings, 0+ Suggestions
Why aren't these errors/warnings/suggestions shown on build, rather than being shown once a corresponding .cs file is opened?
Note - An .editorconfig file is used within the solution. This .editorconfig specifies a set of rules which define when to show Errors, Warnings, and Suggestions within .cs files.
I faced this issue and, for me, what worked was simply following the below steps:
Analyze -> Run code Analysis -> On Solution
This will give all warnings on solution level.
In Visual Studio 2022 I missed many warnings too - via Tools > Options, tab Text Editor > C# > Advanced you find these settings:
Run background code analysis for:
Show compiler errors and warnings for:
and for both you probably want the option Entire solution (instead of Open documents, Current document or None).
You can enable Source code analysis for a single project through the Project Properties dialog. This will in fact install some NuGet packages into the project, which together will run an analysis on each build of the project.
This is not an exact replica of Intellisense analysis, if only because what it will do depends on the selected Rule Set. For the most part I expect this to be at least as thorough as the Intellisense analysis, and probably even more so.
Here is how to install it, and how to select a Rule Set:
For more info, see
https://learn.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview
https://azuredevopslabs.com/labs/devopsserver/codeanalysis/

Lots of squiggly lines after updating to .net core 2.1 - 'may need to supply run time policy'

Don't know why I did, but I updated to .Net Core 2.1 yesterday. Ever since I updated, I am seeing tons of squiggly lines throughout my solution in Visual Studio on mac (so annoying). Here's the warning message -
I think understand the source of the warning. Basically, I am referencing to a lot of 3rd party Nuget packages (Autofac, Serilog, etc.) and they are built with an older version of .Net Core. This is what the warning is trying to tell me I think. But my code works just fine, don't have any issues running it.
After researching a little bit, I think the error is CS1701. It is also added [by default] to be ignored in the Compiler settings for all projects in my solution. This is why I am not seeing this warning reported when I build my project/solution. However, the squiggly's are still shown in the text editor in Visual Studio.
Visual Studio is kind enough to offer a solution to suppress these squiggly lines, by adding a pragma statement at the top of .cs file - #pragma warning disable CS1701 // Assuming assembly reference matches identity. But I am afraid I need to add this line to all .cs file in my solution (there are a lot).
Does anyone know any other better way to suppress these squiggly lines in the text editor, please?
Goto Preferences->Text Editor -> Source Code Analysis -> Code Rules (tab) and change the line
Rule Id="CS1701" Action="Warning" to
Rule Id="CS1701" Action="Hidden"
and press OK.
Wait a for a short while and the lines will disappear.

Cannot run Roslyn Samples under VS2015 CTP 3

I downloaded Roslyn code and built it successfully within VS2014 CTP 3. I am trying to run the samples that came with the source as part of Samples.sln solution. I can build Samples.sln successfully.
I try running ImplementNotifyPropertyChangedCS sample - I made the project the startup project within the solution and pressed "Start Debugging" menu item. As a result I am getting another VS2014 instance. I open a new project within that instance, create a property and try to refactor the property. I am not getting the option to Implement Notify Property Changed refactoring.
I checked the dependencies of the new instance of the visual studio - it does not depend on ImplementNotifyPropertyChangedCS.dll file. I looked at the output window of the first devenv instance - it seems like that ImplementNotifyPropertyChangedCS.dll was loaded but later was unloaded.
Please help.

Categories

Resources