PrivateReflectionDynamicObjectBase error in Unity 2019.2.0f1

rakkar 2 years ago updated by Hasan Al Salman (Community Manager) 2 years ago 24

Version 1.1.1

Assets\Ludiq\Ludiq.PeekCore\Editor\Dependencies\ReflectionMagic\PrivateReflectionDynamicObjectBase.cs(109,34): error CS0121: The call is ambiguous between the following methods or properties: 'System.Reflection.TypeExtensions.GetTypeInfo(System.Type)' and 'System.Reflection.IntrospectionExtensions.GetTypeInfo(System.Type)'

Unity Version:
Peek Version:
Pending Review

Hi Rakkar,

Sorry you're experiencing this issue and thanks for the report.

Can you provide some more details about your setup? Which target platform are you building for? That sounds like an error with Windows Store versions of reflection.

I tried Peek in a new project using the same Unity version and target and it worked. Peek failing in my main project could be due to the use of a DLL, which contains about half the code for the project.

I tried the DLL in a new project and it worked fine too. I'm not sure what the problem is, which is unfortunate since Peek is such a huge productivity booster.

Pending Review

Hi Rakkar,

This used to be an error in the experimental .NET 4.x runtime from Unity, but in 2019.x, it should no longer be an issue, so I'm puzzled you're getting it in 2019.2. 

I will attempt a manual disambiguation for the next version, but in the mean time, can you confirm your project is not from an earlier version of Unity?

EDIT: It would not be trivial to disambiguate manually considering how often this method is used. My educated guess is that the DLL with half your project in it uses an outdated version of .NET or Unity references to be compiled? 

From your screenshot, I also don't understand why Scripting Backend and Api Compatibility Level are grayed out? Is this because of some configuration or target platform elsewhere? I can't seem to trigger that here.

Scripting and API compatibility level may have been greyed out due to settings not being checked out at the time of the first screenshot?

I don't think the problem is the DLL, as I exported the DLL to a new project and it worked. Here are the settings regardless.


"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.addressables": "1.1.7",
"com.unity.analytics": "3.3.2",
"com.unity.ext.nunit": "1.0.0",
"com.unity.ide.rider": "1.0.8",
"com.unity.ide.vscode": "1.0.7",
"com.unity.package-manager-ui": "2.2.0",
"com.unity.playablegraph-visualizer": "0.2.1-preview.3",
"com.unity.postprocessing": "2.1.7",
"com.unity.probuilder": "4.0.5",
"com.unity.progrids": "3.0.3-preview.4",
"com.unity.test-framework": "1.0.13",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.1.0",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"

Not sure if this is relevant, but it says "Assembly Info" Targets .NET 4.x

Need More Information

Hi Rakkar,

First, I apologize about the late reply on this.

If the DLL isn't the problem and the Unity version either, can you try isolating the issue further by making your test project resemble your main project? Whenever Peek starts failing, let me know what was the last operation or modification you did and we'll be able to work from that cause.

I'm sorry I can't be of further help, it's hard to reproduce from large projects like yours.

I had attempted earlier to repro in an isolated test project but was unable to. We'll have to leave this one unresolved.

I'm having exactly the same problem. It happens as soon as I include Yarn Spinner from here https://github.com/YarnSpinnerTool/YarnSpinner/releases

It does not matter if you use the source code variant or the compiled variant. The problem seems to be that its dependencies "Antlr4.Runtime.Standard.dll", "CsvHelper.dll" and "Newtonsoft.Json.dll" are targeting .NET 3.5.

What are our options in this case? I have no experience using multiple libraries targeting different .NET versions.

Rakkar, you seem to be using Yarn Spinner, too?

Yes I am also using Yarn SPinner

Pending Review

Hi SchroedingersCat,

Thanks for the additional information. Now that there is some way to look into reproducing this bug I'll reopen it and have a look at the exact symptoms and possible fixes.

I'm not sure if the dev is able to fix this on his side. But if anybody runs into this problem and is using YarnSpinner 0.9.11 from here https://github.com/YarnSpinnerTool/YarnSpinner/releases

Then all you need to do is to update the dependency "CsvHelper" from here to a more recent version: https://www.nuget.org/packages/CsvHelper/

I'm using v12.2.2 . Simply download the package and open the nupkg file with a zip tool and pick the dll from "lib\netstandard2.0\". Or use this file CsvHelper.dll

Just copy that over the dll in "YarnSpinner\Code".

Cannot Fix

Hi SchroedingersCat, thanks for the follow up!

So I just reproduced this on my end and indeed there's nothing I can do to fix it, to my knowledge.

The CsvHelper library includes its own System.Reflection.TypeInfo type definition, which is not something that any library should ever do (redefining a core type in the System namespace). I'm puzzled as to why they do this. I'm guessing they tried to statically link some newer unavailable .NET functionality, but that's very hacky. The issue is on their end.

The only way to disambiguate types with the same name in two different assemblies is an extern alias. This is however not possible in Unity because we don't get to configure the build options from the compiler, so we can't define the /reference option to map it to mscorlib or CsvHelper.

As SchroedingersCat pointed out, replacing the CsvHelper DLL with a newer DLL seems to fix the issue.

However, you might get compile errors then about missing test methods from NUnit. This is because CsvHelper apparently also statically linked NUnit (which is, again, not something you should do). You can fix the NUnit compile errors by adding the "Custom NUnit" package from the Unity Package Manager. 

Then the project compiles!

Hi Lazlo,

thank you for the detailed response. How did you analyze the library to get this information?

EDIT: I opened a bug report at the YarnSpinner repo here https://github.com/YarnSpinnerTool/YarnSpinner/issues/185

YarnSpinner 1.0.0 (and 1.0.1) have been released. This issue has been fixed with these versions. https://github.com/YarnSpinnerTool/YarnSpinner/releases