fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

The type 'Object' is required here and is unavailable #380

Closed TimLariviere closed 2 years ago

TimLariviere commented 2 years ago

Hello! I'm stuck with an assembly error while developing a generative type provider, and I can't figure out what I'm doing wrong.

Context

When doing android development, adding any type of resource (image, sound, colors, styles, etc) will generate a unique id for that resource that developers need to use. In Xamarin.Android, those ids are generated in a Resource.designer.cs file (written in C# - basically a bunch of classes with const int fields).

Of course, in F# Android projects, that file is not included preventing us from using those ids. To work around that, https://github.com/xamarin/Xamarin.Android.FSharp.ResourceProvider has been created.

It's a type provider that compiles Resource.designer.cs into a dll and loads it in the ITypeProvider interface.

Unfortunately, this type provider is no longer maintained and is a pain for Android development using F#. (https://github.com/dotnet/fsharp/issues/12640, https://github.com/dotnet/fsharp/issues/10837, https://github.com/xamarin/Xamarin.Android.FSharp.ResourceProvider/issues/9, https://github.com/xamarin/Xamarin.Android.FSharp.ResourceProvider/issues/11, https://github.com/xamarin/xamarin-android/issues/6404, https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/376)

So I took over that task and made a new type provider using the latest template.

You can find the project here: https://github.com/fabulousfx/FSharp.Android.ResourceProvider

Problem

I have been following the same logic than the original XA.FSharp.ResourceProvider, meaning:

But when doing this, either by command line (dotnet build) or in IDE, I get the following error in the project using the type provider:

error FS1108: The type 'Object' is required here and is unavailable. You must add a reference to assembly 'System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
image

Weirdly, if I load the compiled dll directly in the target project (<Reference Include="ProvidedTypes.dll" />), it works perfectly well. But if I let the type provider include the assembly for me, it fails.

I did a lot of tests to try and find the source of the issue, but nothing works. Assemblies locations match, everything should be good...

Would you have an idea what I'm doing wrong?

How to reproduce

Prerequisites:

Then run dotnet build tests/FSharp.Android.ResourceProvider.Tests -c release -v diag

You should see a build error with the reported message.

@dsyme @KevinRansom

TimLariviere commented 2 years ago

I abandoned using Type Provider for this use case. Went with a simple MSBuild target https://github.com/fabulousfx/FSharp.Android.Resource

dsyme commented 2 years ago

Much better! Thanks

The TP was wrong for this.