How to reference method in xml comments when using multiple frameworks? - c#

I have a project with target frameworks for net6 and net7, and i'm seeing the following warning pop up:
error CS1574: XML comment has cref attribute 'CreateParameter(DbCommand, string, object, bool?)' that could not be resolved
This seems to be because there are multiple versions of that function defined in the framework;
So the method presumably cannot be found when using net7.
How can i make it so the cref picks the right method?

Related

Why am I not getting warnings for missing xml documentation on public API?

My C# project (a Unity Package library) is not getting warnings on missing xmldoc of public classes, properties or methods.
I want to ensure all of my public API has XML documentation in code, but I've noticed there's undocumented public methods with no warnings. The csproj for my lib was basically copied from the csproj auto-generated by Unity, with a few changes. I'm not suppressing any warnings related to documentation as far as I can tell.
What I wanted was basically CS1591:
Missing XML comment for publicly visible type or member 'Type_or_Member'
The DocumentationFile compiler option was specified, but one or more constructs did not have comments.
It seems I have to make sure the <DocumentationFile> tag is specified to a non-empty file path (and WarningLevel 4 is not disabled) in the csproj.
<DocumentationFile>some/path/AssemblyName.xml</DocumentationFile>
I hadn't specified it before because I don't actually need documentation in a separate xml if my lib will be distributed as source code (Unity already picks the docs from code comments). I would need it if I had to compile the dll.
After specifying the DocumentationFile to some temp path, VSCode / Omnisharp will emit warnings like CS1591, CS0419.

Ambiguous reference error in OpenApi-generated c# code

I'm using OpenAPI Generator to generate client libraries for my c# API. I am having issues generating a c# client, because one of my models is called Environment. The generated service code to manipulate this model causes the build of the project to fail because it is an ambiguous reference between it's own model and .Net's System.Environment.
The exact error I'm seeing is
Api/EnvironmentApi.cs(87,42): error CS0104: 'Environment' is an ambiguous reference between 'MyProject.Model.Environment' and 'System.Environment'
Is there some way to tell openapi-generator to fully-qualify the class names in the generated code so that it won't clash? i.e. so it generates something like
DoSomething<MyProject.Model.Environment>(...) instead of DoSomething<Environment>(...)
It's been a while since the request was opened for swagger: https://github.com/swagger-api/swagger-codegen/issues/2630
Bear in mind that I'm referring swagger as it is the project that was forked to make openapi generator.
https://github.com/OpenAPITools/openapi-generator/blob/master/docs/migration-from-swagger-codegen.md#new-fully-qualified-name-for-the-classes
OpenAPI Generator is a fork of swagger-codegen between version 2.3.1 and 2.4.0
So the answer is most probably no.

Ambiguous call when using certain libraries at once

In my Xamarin project I'm using ReactiveUI and Firebase.Xamarin. When these two libraries are being used at once, any attempt to use System.Reactive.Linq.Observable extension methods such as Where or Select results in compile time error:
The call is ambiguous between the following methods or properties: 'System.Reactive.Linq.Observable.Where(System.IObservable, System.Func)' and 'System.Reactive.Linq.Observable.Where(System.IObservable, System.Func)'
I presume this is being caused by both of these libraries defining/referencing the same methods in same namespaces. How can I fix that?
It is likely that you are loading more than one version of the assembly that defines that namespace. It may be that the assemblies that you refer to load a common dependency. If they load different versions of that assembly you would get this error.
Ensure that you are using versions of the two libraries that depend on the same version of the dependant assembly.
Firebase.Xamarin is no longer maintained so if I wanted to follow #PhilipSmith advice I would have to use ReactiveUI version that is over 2 years old. I didn't wanted to do it so I decided to clone Firebase.Xamarin since its OSS and add it to my solution as another project with intention to alter the ReactiveUI version it was referencing. But when I added is as a referenced project the error disappeared.

Not all namespaces are included into Sandcastle build for documentation

I have a C# project with two namespaces in one solution. I've documented all the classes/functions/members/etc in both namespaces. As this project is a small research project, the namespaces are DocTestLibrary and DocTestLibrary.Events. However, when I try to create documentation from it via Sandcastle, it will only create documentation for the DocTestLibrary namespace. Is there any setting that I need to make in Sandcastle to make this work? I doubt it though, as I've scoured through most of them.
The strange thing is, Doxygen is able to generate documentation just fine.
As to provide some more information, I've checked the log that Sandcastle produces for the build.
It seems that this entry is causing the rest not to be displayed.
Warn: ResolveReferenceLinksComponent2: Unknown reference link target 'T:DocTestLibrary.Events.DemoEvent'.
I also found out something else.
The DocTestLibrary namespace consists of two classes:
TestClass
StaticHelper
As the name implies, the StaticHelper is a helper-class with only static methods. Yet Sandcastle also denies to process this file. Only the TestClass get's processed. It only boggles me that there isn't an entry about this in the log though.
In my sandcastle project it would always only include a single namespace of a total 5. The problem was that I did not check Include root namespace container under the section Help File.
Now all my namespaces are listed unter a root namespace.
Are all your types in DocTestLibrary.Events internal by any chance? By default, I believe Sandcastle only generates documentation for public types.
I've found this issue can be fixed by manually setting the classes you want documented in Edit API Filter under Project Properties -> Visibility.
It seems that this issue is fixed by setting the DocumentInternals in the Visibility properties section in the Sandcastle project. I wonder why this is, as no code is declared internal...
I guess I'll be playing around some more...

"Missing compiler required member" error being thrown multiple times with almost no changes to code

Today after deploying some changes to a C# MVC site that I run, I went back to make some more modifications and came across this error:
Missing compiler required member System.Runtime.CompilerServices.ExtensionAttribute..ctor
The error is a bit vague (other than it's description, obviously) as it doesn't give me a file, line, or column to reference, only the project. Also, it throws the error a total of 20 times. I only made three changes to the code between the time I deployed (it was completely functional at that time) and now. I reverted my changes and it is still throwing the same error which makes no sense to me.
I haven't found a lot of information on this error on SO or Google, other than this guys solution and a couple references to some Mono project errors (I'm not using Mono). The solution the guy above gives requires adding a class definition that will allow the compiler to resolve the reference. I don't particularly want to do this because I haven't needed to do it up until this point and it will just muddy my code.
Just curious if anyone has run across this before.
In my case it was because the project was not referencing Microsoft.CSharp. Once I added a reference to that assembly, it compiled just fine.
I don't know if anyone else has experienced this, but I suddenly ran into this error after adding some code utilizing dynamic types and incorporating WebAPI into a project that originated as a TypeScript application in VS2013. Simply adding a reference to Microsoft.CSharp resolved my issue.
Hope this helps someone else.
This error usually means either your project is compiling against .NET 2.0 or you aren't referencing the correct version of System.Core.dll
For a near duplicate question, see Error when using extension methods in C#
I ran into this situation as well today. In my case I was referencing the Newton.Json.Net dll v3.5 in my .NET 4.0 application. I realized that I wasnt even using this library, thus once I removed it from my references, it no longer gave me the compiler error.
Problem solved!!!
The actual error comes from the fact that your 2.0 assembly that causes the error contains this code:
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
The Code Above allows the .NET 2.0 Assembly to use extension methods (see Using extension methods in .NET 2.0?). While it confuses the compiler if you target .NET 4.0 and reference a 2.0 Assembly (containing above code) as the mscorlib.dll(4.0) contains the same class in the same namespace.
I fixed this
by compiling the original 2.0 assembly again without the attribute targeting 4.0
by removing the assembly (obviously)
by adding a third Extension Attribute in the target you compile (it seems to overrule the referenced definitions)
Writing this code somewhere in your project may solve your problem. It works for me
namespace System.Runtime.CompilerServices
{
public class ExtensionAttribute : Attribute { }
}
Probably you use dynamic keyword In .NetStandard Class library project. If so, you need to add a reference to Microsoft.CSharp library in the project. Hope it will resolve your problem.
NLog.dll 2.0 referenced from a .NET 4.0 project can cause this too.
I don't have a correct solution, but I'll add my data point:
In my case the error is caused by referencing GoogleSearchAPINet20
Here is what happens:
I close the solution that builds
I open the solution again. It still builds
As soon as I make any change and try to build, I get 19 "Missing compiler required member ..." errors
I remove the reference to GoogleSearchAPINet20
I add back the reference to GoogleSearchAPINet20
I build the solution. It builds without errors
I can now make code changes, build or perform any other actions with solution correctly as long as my Visual Studio is open
I close Visual Studio
Repeat from step one
I'm not referencing System.Core.dll in my solution at all and my target framework is .NET 4.
I'm a bit annoyed at this point ...
Got this error when trying to use async Tasks against .NET 4.0. Updating Target Framework to 4.5.2 fixed the problem.
I hit the same set of exceptions after I added some async methods to a winforms project. I needed to bump my .NET version from 4 to 4.5
For me, the problem occure when I add asynchronous method with async Task await in my .net4.0 project !
With previous versions of the .NET-Framework 4.5, you must install this package:
Install-package Microsoft.Bcl.Async –pre
or
Install-Package Microsoft.CompilerServices.AsyncTargetingPack
more info on Nuget or Nuget

Categories

Resources