Warning that cannot be erased in C #

2 minute read

This is a list of warnings that cannot be erased using C #.
I will add it as needed when I notice it.

Overview

It became a hot topic in the broadcast of ++ C ++; administrator Iwanaga on August 16th, so I built an article.
https://youtu.be/-_QGGvT5FEw?t=6485

Of course you can turn it off with #pragma warning disable, but ignore it.

List

CS0067: event’event’ is not used

Microsoft Docs

As explained, this is a warning that appears when you have created an event but are not using it.
Of course, if you can delete it, you can delete it, but if you inherit the interface including the event, you can not delete it.
Can you actually erase it?

    public class ShowMessageCommand : ICommand
    {
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter) => true;

        public void Execute(object parameter)
        {
            Application.ShowMessage(parameter?.ToString());
        }
    }

CS0612:’member’ is old format

Microsoft Docs

This is a warning when you reference a member who has marked [Obsolete].
Of course, you should avoid it, but if you need to access the old code for compatibility or migration purposes, you may have to leave one warning.

CS1998: This async method does not have an “await” operator and runs synchronously.

This async method does not have the’await’operator, so it runs synchronously. Consider using the’await’operator to wait for non-blocking API calls or using’await Task.Run (…)’ to perform CPU-centric processing on background threads. please.

I think many people who use ʻasync are having trouble with this. I tell you, in most cases this can be erased. Or rather, you should be able to erase everything. Specifically, use Task.CompletedTask; and Task.FromResult (); `.

Func<Task> a = async () => { DoSomething(); };
Func<Task<bool>> b = async () => true;

These are rewritten as: Among them, the refactoring function will support it.

Func<Task> a = () => { 
    DoSomething();
    return Task.CompletedTask;
};
Func<Task<bool>> b = () => Task.FromResult(true);

But it’s a bit redundant, isn’t it?
For example this

DoSomething(async (_)=>(null,null));

And this

DoSomething(_ => Task.FromResult<(Func<bool> FirstResult, Func<bool> SecondResult)>((null, null)));

Then you will want to use the former.
This is an example where a delegate is involved in tuple, and type inference does not work. If it’s just a tuple, it will work.
Personally recent example, and all of them were (null, null) at that time, so I put them together in one place. But if not, I left a warning (although I could create another function that returns tuples).

The reference component’Microsoft.VCLibs’ was not found.

A warning that has been issued for a while recently. Mystery is.
If you delete the reference, it will not work, and if you leave it alone, there will be no problem, so leave it alone.
As a tentative measure, I think that “Restore Nuget package”, “Clean solution”, “Delete .vs folder” are standard.

I posted it because I’m interested in it recently, but it’s a little different from the nature of this article.
Article in Xamarin Forms.
However, there are times when this kind of mystery warning cannot be erased.