How to lose time thanks to VS (CS1106 Extension method must be defined ...)

This forum is meant for anything you would like to share with other visitors
Post Reply
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by ic2 »

Just in case you come around this too:

I just added a C# method to my DLL with other C# methods. But when I compiled the solution, I got:

Error CS1106 Extension method must be defined in a non-generic static class

This also caused the error Metadata file '.dll' could not be found, which is Visual Studio slang for: there is a compiler error in that dl lso we can't comile dll's including that...

First issue is that the "Extensions method" error points to the top of my program, where the class starts. If I hadn't just inserted that method myself, which caused the error, I think there was no way that I could find the cause of the error!

Second, I didn't understand why other methods looking the same worked and this one didn't. I already removed static (no need for that that I could think of) and after a long time of trying, found that my method said:

public bool IsDataRowEmpty(this DataRow dr)

Removing "this" solved the problem.

Took me well over an hour to find it. Did I ever write I hate every second I work in VS? Oh yes, I did.

Dick
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by Chris »

Hi Dick,

This is a problem indeed, but it does not have to do with VS, it's a problem in the c# compiler. If you compile the same c# code in XIDE, you will get the same behavior and there's nothing XIDE (or VS) that can do about it.

I checked and indeed the compiler error points to the class, not to the incorrectly defined method, which makes it extremely difficult to find the cause of the problem. We did have (or maybe still have) several such problems in X#, but they were fixed after people reported them. Try reporting this to MS, who knows maybe you will get lucky this time :) (and possibly help others who will face the same problem in the future)

PS. But of course it will help if you start your message to MS with "Hello, I think I found a problem in the c# compiler", instead of "This %*$&# Visual Studio is total %&^*#@ and I lost half my day trying to find my way around this &*^&^*@ problem that I will report to you", even though I agree it is very tempting to use version #2 :)
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by ic2 »

Hello Chris,

Hmm, I indeed always select option 2 :P

The problem with most issues reported to Microsoft, even if phrased very politely, is that they close most of them with "Not enough info to..." even if the person who reported couldn't state it more clearly.

But I'll give it a try. And include the totally unusable compiler error caused by 'this'.

Dick
VR
Posts: 102
Joined: Sun Aug 23, 2020 3:07 pm
Location: Italy

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by VR »

Hello Dick,

I recreated your problem in c#. As you said, i'll get the CS1106 error which links to this page: https://docs.microsoft.com/en-us/dotnet ... Dk(CS1106)

With the knowledge, that the "this" keyword before the first parameter of a static method is used to define a extension method (which IMHO is an awesome contruct for certain usecases) and the example on the page, it should not take long to understand the problem.

If I do the same in x# code, the error page just states "Extension method must be defined in a non-generic static class".

Sugestion for @Chris: It might be sometimes helpful, that the xs-compiler-error-pages for all the roslyn-compiler errors have a link at the bottom to the corrisponding cs-compiler-error-page.

Volkmar
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by robert »

Chris,
VR wrote: Sugestion for @Chris: It might be sometimes helpful, that the xs-compiler-error-pages for all the roslyn-compiler errors have a link at the bottom to the corrosponding cs-compiler-error-page.
Yes Chris, why don't you do that ?

Volkmar,
Chris does not maintain the help file.
And unfortunately not all the Roslyn errors are documented too.
So we would have to manually check which errors have a relevant page and which don't, or simply insert links in the helpfile without checking and hope that the page exists..

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by ic2 »

Hello Volkmar,

Probably Microsoft gives your more information on this URL than they give me :) but the very limited information absolutely gives me no clue about "this" being the culprit.

The code was from a StackOverflow sample (and included 'this').

I wish Microsoft transferred half of their bullshit writers to writing useful help pages.

Dick
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by FFF »

ic2 wrote:I wish Microsoft transferred half of their bushtit writers to writing useful help pages.
Nice typo :)
But i second that. I have the "pleasure" to work in Word2016 now the last 4 weeks, 60+ hours a week. It's "help" is ... And given, that this product is more than 5 years old, the number of articles, which are "machine translated to bring you the information as fast as possible" is astounding, to put it mildly.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by ic2 »

Hello Karl,

Ah yes, the type is actually the suggestion in my browser as it showed red underlined, so it was a type and I changed it into something totally different because I didn't read what the suggestion was haha.

I'll change it for now and anyone reading this later can see what it was in your reaction :P

Dick
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by robert »

Dick
ic2 wrote: I wish Microsoft transferred half of their bullshit writers to writing useful help pages.
I know that MS has a quite large team working on the Docs.
I have had the pleasure to meet some of them during an event for Visual Studio partners.
And they were quite different from the developers. I got the impression that Ms tried to reach its diversity quota bu hiring quite diverse people. And I got the impression that some of them did not really understand the things they were documenting.

During our meeting I suggested that they should add functionality to the website to write example code in "pseudo" language and to use a source code generator to then generate examples in C#, VB, F#, C++ etc. And of course to also allow 3rd parties (X#) to contribute with their own code generator.
They were flabbergasted. They did not know that something like that was possible.
I explained them (and showed them) that this was using tools that were already documented by them on their own website.
In the end I got the impression that did not like the idea at all because implementing that would probably mean that a few of their colleagues would loose their job.

In other words: The developers and documentation writers at Microsoft are completely separated teams.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to lose time thanks to VS (CS1106 Extension method must be defined ...)

Post by ic2 »

Hello Robert,

I met several nice people at Microsoft too. And I was even once asked by a senior VS developer to get in touch after I filled in the evaluation form. That was a surprise. I asked him to watch and see me working with VO and then I performed the same task in VS, where everything was much slower, I couldn't find the last modified code like in VO with 2 mouse clicks and a small error in an entity did not get me 500 errors in all other entities. He was quite impressed with our old VO ("Wow, that is indeed lightning fast") but I have not seen a single development since in VS closing that gap (not did I really expect so).

The poor documentation like for that error CS1106 is an example that there may be a large independent documentation staff but that doesn't necessarily have a positive result.

Together with what you write it supports my idea that Microsoft consists of 100's of smaller groups who hardly communicate with each other and almost none of them perform a job comparable with what you do with X#.

Does this mean X# is perfect? No, neither is my or probably any software. I hardly ever install an upgrade immediately and await the first reported bugs to be solved. For X#, most are solved in that next version which also often follows the previous within days or weeks. With Microsoft software, severe bugs are solved soon too (but: we come around bugs in W10, Office, from which you think "how could this ever have been released") but many bugs are never solved.

So yes, there are some clever guys or good teams. But the total picture is absolutely not in line with a software company with their resources. Imagine you had the budget of one of their smaller teams. X# would not have just been a very clever environment, but probably the best compiler and language and (x)IDE ever written.

Dick
Post Reply