Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TimLariviere opened this issue Jan 31, 2022 Discussed in #379 · 2 comments
Closed

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

TimLariviere opened this issue Jan 31, 2022 Discussed in #379 · 2 comments

Comments

@TimLariviere
Copy link
Member

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#. (dotnet/fsharp#12640, dotnet/fsharp#10837, xamarin/Xamarin.Android.FSharp.ResourceProvider#9, xamarin/Xamarin.Android.FSharp.ResourceProvider#11, dotnet/android#6404, #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:

  • Compile Resource.designer.cs into its own dll (using Roslyn)
  • Assembly.Load that dll to get the System.Types
  • Feed the dll bytes and types to the interface ITypeProvider

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
Copy link
Member Author

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

@dsyme
Copy link
Contributor

dsyme commented Feb 3, 2022

Much better! Thanks

The TP was wrong for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants