Null kann nicht in den Typparameter „T1“ konvertiert werden, da es sich um einen Werttyp handeln könnte. Erwägen Sie sta

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Null kann nicht in den Typparameter „T1“ konvertiert werden, da es sich um einen Werttyp handeln könnte. Erwägen Sie sta

by Guest » 15 Jan 2025, 17:18

Ich habe einen wirklich seltsamen Fehler. Hier ist ein MRE:

Code: Select all

var outputs = new (
(Typing First, Typing Second) a,
(Typing First, Typing Second) b,
(Typing First, Typing Second) c,
(Typing First, Typing Second) d,
(Typing First, Typing Second)? e,
(Typing First, Typing Second) f,
(Typing First, Typing Second)? g,
(Typing First, Typing Second)? h
)[2];

outputs[0] = (
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing()),
(new Typing(), new Typing())
);

outputs[0].h = null;  // Cannot convert null to type parameter 'T1' because it could be a value type. Consider using 'default(T)' instead.

class Typing
{
}
Sie fragen sich vielleicht, warum dieser MRE so „nicht minimal“ ist. Nun, wenn ich das Tupel kleiner mache (indem ich zum Beispiel f oder g entferne), erhalte ich keinen Fehler mehr.
Beweis:
Fehler:
Image
Kein Fehler :
Image

Möglicherweise müssen Sie dies zu Ihrem csproj hinzufügen, um den Fehler zu sehen:

Code: Select all

enable
CS8600;CS8602;CS8603 
Details:

Code: Select all

JetBrains Rider 2024.3.3
Build #RD-243.22562.250, built on December 23, 2024
Licensed to **************************
Subscription is active until *******************
Runtime version: 21.0.5+8-b631.28 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
.NET Core v8.0.4 x64 (Server GC)
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4078M
Cores: 16
Registry:
ide.experimental.ui=true
i18n.locale=
llm.show.ai.promotion.window.on.start=false
Non-Bundled Plugins:
com.jetbrains.space (243.21565.122)
com.chesterccw.excelreader (2024.11.1-243)
me.lensvol.blackconnect (0.6.2)
com.github.copilot (1.5.30-242)
com.intellij.resharper.azure (4.3.8)

Top