Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unable to cast object of type to type

オープン
#258 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp, fsharp, graphql
領域
api, backend

調査の方向性

再現は Define.Union、resolveType、resolveValue を中心としている。まず、生成された C# Response 型を使って提供された F# の例を実行する。Foo ブランチが Result.Foo に解決され、FooResult-to-Response.Foo のキャスト例外が発生しなければ完了。

索引モデルが issue の本文から書いたものです。

説明

Description

I am receiving an error when converting a response value. The error I receive is "Unable to cast object of type FooResult to type Foo where FooResult is a value of a discriminated Union. Since it compiles, I am unsure of how to debug the issue or how to diagnose the error.

Repro steps

My 'In type Response is a generated C# class provided by a Protobuf generator and my `Out type Result is a Descriminated Union type such that:

public sealed partial class Response {
  public global::Foo Foo { }
  public GetUnionOneOfCase GetUnionCase { }
let FooType =
    Define.Object<Foo>
        (name = "Foo",
         fields = [ Define.Field("message", String, (fun _ e -> e.Message)) ])

type Result =
  | FooResult of Foo
  | BarResult of Bar

let GetResultType = 
  Define.Union<Response, Result>
    (name = "Response",
     options = [ FooType; BarType ],
     resolveType =
       (fun response ->
       match response.GetUnionCase with
       | Response.GetUnionOneofCase.Foo -> upcase FooType
       | Response.GetUnionOneofCase.Bar -> upcase BarType),
     resolveValue = 
       (fun response ->
       match response.GetUnionCase with
       | Response.GetUnionOneofCase.Foo -> FooResult response.Foo
       | Response.GetUnionOneofCase.Bar -> BarResult response.Bar))
Expected behavior

I expect this to resolve response.Foo as Result.Foo.

Actual behavior

System.Exception: Unable to cast object of type 'FooResult' to type 'Response.Foo'

Related information
  • OSX
  • Dotnet Core
主要言語
F#
スター
406
フォーク
74
平均マージ
1日 8時間
マージ済み PR(30日)
14

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fsprojects/FSharp.Data.GraphQL のほかの issue

fsprojects/FSharp.Data.GraphQL の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。