Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Here is a forum for reporting failure to Arbor developer.
Please read the forum rules carefully and enter the information necessary to confirm the problem.

Note:
  • Please read the "Update Guide" carefully when updating Arbor.
  • The bugs that we already know are summarized in "Known Issues", so please check once.
  • Please check ReleaseNote and use the latest version if possible before reporting a bug.
  • Unity beta and alpha versions are not supported. Please use the official release version.
  • In principle, defects caused by the introduction of other assets are not supported. If you find a defect, please report it after isolating which asset is the problem.

ここは、Arbor開発者へ不具合を報告するためのフォーラムです。
フォーラムルールをよく読み、不具合確認に必要な情報を記載するようお願いします。

注意点:
  • Arborを更新する際は「アップデートガイド」をよく読み行ってください。
  • 既に把握している不具合は「既知の問題」にまとめてありますので一度確認してみてください。
  • 不具合報告をする前にReleaseNoteを確認し、なるべく最新バージョンを使用して下さい。
  • Unityのベータ版およびアルファ版はサポート対象外です。正式リリース版をご利用ください。
  • 他アセット導入による不具合は原則サポート対象外です。不具合を見つけた場合はどのアセットの問題であるか切り分けた上でのご報告をお願いいたします。

Forum rules
The items necessary for reporting are as follows.
  • OS(Required)
  • Unity version(Required)
  • Arbor version(Required)
  • How to reproduce(Required)
    The reproduction method should be described accurately so that anyone can read the same procedure.
    If you do not know the exact reproduction procedure, as long as you can remember it, so please tell us what you were doing immediately before and the last time you edited it.
  • Build platform
  • Reproduction project (Minimum configuration not including Arbor and other assets) or video

Note:
  • Please read the "Update Guide" carefully when updating Arbor.
  • The bugs that we already know are summarized in "Known Issues", so please check once.
  • Please check ReleaseNote and use the latest version if possible before reporting a bug.
  • Unity beta and alpha versions are not supported. Please use the official release version.
  • In principle, defects caused by the introduction of other assets are not supported. If you find a defect, please report it after isolating which asset is the problem.

報告に必要な項目は以下の通りです。
  • OS(必須)
  • Unityバージョン(必須)
  • Arborバージョン(必須)
  • 再現方法(必須)
    再現方法については、誰が読んでも同様の手順を行えるよう正確に記述するようにお願いいたします。
    もし正確な再現手順が不明な場合、覚えている限りで構いませんので直前に行っていたことや最後に編集した時のことを教えてください。
  • ビルドプラットフォーム
  • 再現プロジェクト(Arborや他アセットなどを含まない最小構成)もしくは動画

注意点:
  • Arborを更新する際は「アップデートガイド」をよく読み行ってください。
  • 既に把握している不具合は「既知の問題」にまとめてありますので一度確認してみてください。
  • 不具合報告をする前にReleaseNoteを確認し、なるべく最新バージョンを使用して下さい。
  • Unityのベータ版およびアルファ版はサポート対象外です。正式リリース版をご利用ください。
  • 他アセット導入による不具合は原則サポート対象外です。不具合を見つけた場合はどのアセットの問題であるか切り分けた上でのご報告をお願いいたします。
chorome

Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by chorome »

  • OS:Windows11
  • Unityバージョン:2022.3.5f1
  • Arborバージョン:3.9.8
Arborと特定のdll(Unity環境では参照が足りないdll)と併用するとReflectionを用いたライブラリが一部動作しなくなるようです。

手元の環境では以下の組み合わせで上記の現象が発生しました。
Unity環境では参照が足りないdll:UnitGenerator
Reflectionを用いたライブラリ:Rider Flow、netcode for GameObject(のNetworkManagerEditor)

■再現方法
1. Unityプロジェクトを新規作成
2. UnitGeneratorのdllをインポート、dllのインスペクターでAny Platform・Include Platformをすべて無効にし、「RoslynAnalyzer」ラベルをつける
3. RiderFlowをインポート
4. RiderFlowの各機能が動作することを確認する
5. Arborをインポート
6. RiderFlowが動作しなくなる

■調査結果
Arborの入ったプロジェクトだと AppDomain.CurrentDomain.GetAssemblies() で返ってくる Assembly[] に UnitGenerator の Assembly が含まれるようになります(Arborが入ってないプロジェクトだと含まれない)。UnitGenerator の Assembly の GetTypes() を呼ぶと以下の例外が発生します。

Code: Select all

ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.
UnitGenerator は Unity 以外の環境でも利用することが想定されたライブラリなので、他の環境で必要な参照が何かしらが足りてないのかもしれません。ただ、この問題は UnitGenerator が AppDomain.CurrentDomain.GetAssemblies() に含まれなければ気にする必要はないはずの問題です。

Arborの入ったプロジェクトだと AppDomain.CurrentDomain.GetAssemblies() に UnitGenerator が含まれるようになるのは、ArborEditor.ClassList でプロジェクト内の dll を読み込んでいるのが原因のようでした。

■個人的推察
ArborEditor.ClassList.IsValidPlugin(PluginImporter pluginImporter) の中の if (!pluginImporter.GetCompatibleWithEditor()) って実は if (pluginImporter.GetCompatibleWithEditor()) の間違いだったりしませんか?
(コードの意図とか全然理解できてないのでまったく違ったこと言ってたらすみません…)
chorome

Re: Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by chorome »

純粋にArborの問題という訳でもない件で申し訳ないのですが、こういう現象がありましたという報告です🙇
User avatar
caitsithware
管理人
Posts: 493
Joined: 2015/08/17 12:41

Re: Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by caitsithware »

ご報告ありがとうございます。

RoslynAnalyzer(SourceGenerator)専用DLLをインポートしていると起きる問題のようですね。
以下の方法を試していただけますか。

暫定対処方法
  1. Assets/Plugins/Arbor/Internal/Editor/Reflection/ClassList.csを開く
  2. ファイル先頭あたりに以下のコードを追加

    Code: Select all

    using System.Linq;
    
  3. 151行目あたりに以下のコードを追加

    Code: Select all

    var labels = AssetDatabase.GetLabels(pluginImporter);
    if (labels != null && labels.Contains("RoslynAnalyzer"))
    {
    	return false;
    }
    
chorome

Re: Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by chorome »

早急なご確認ありがとうございます。

ご提案いただいた対応方法ですとPackageManager経由でインポートされたdllについては対処できないのかもしれません…。

UnityTransportの Unity.Transport.Analyzer.dll が読み込まれてしまうようです。
User avatar
caitsithware
管理人
Posts: 493
Joined: 2015/08/17 12:41

Re: Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by caitsithware »

その場合はラベルがついていないようですね。
どのプラットフォームにも含まれないDLLを除外する必要もありそうです。

暫定対処方法
  1. 再びAssets/Plugins/Arbor/Internal/Editor/Reflection/ClassList.csを開く
  2. 157行目から166行目にある以下のコードを削除

    Code: Select all

    if (pluginImporter.GetCompatibleWithAnyPlatform())
    {
    	return true;
    }
    
    if (!pluginImporter.GetCompatibleWithEditor())
    {
    	return true;
    }
    
chorome

Re: Arborと特定のdllを併用するとReflectionを用いたライブラリが一部動作しなくなる

Post by chorome »

ReflectionTypeLoadExceptionでなくなりました!ありがとうございます!!
Post Reply