Fable: System.Uri Type not found

Created on 3 Jul 2017  路  8Comments  路  Source: fable-compiler/Fable

Description

I tried to add replacements for some of the System.Uri static methods. The UnescapeDataString in particular. But when I use the Uri Type somewhere in the problem Fable throws an error even before replacing when it tried to load the FSharp AST.

Repro code

Please provide the F# code to reproduce the problem.

System.Uri.UnescapeDataString "Kevin+van+Zonneveld%21" |> equal "Kevin van Zonneveld!"

/Users/kdummann/source/fsharp/Fable/src/tests/Main/MiscTests.fs(830,11): (830,14) error FSHARP: The value, constructor, namespace or type 'Uri' is not defined.

Expected and actual results

At least the FSharp AST should be build and Fable should complain afterwards that there is no replacement. Any Ideas why parsing the AST already fails in this case?

Most helpful comment

Ok, thanks for the confirmation. Hopefully we can move soon to netcore 2.0 and leave behind all these holes in the API and crazy references 馃槃

All 8 comments

Hmm, I guess a reference is missing somewhere. Does the code work if you compile it as a netcoreapp? @ncave Maybe we're missing something here?

Works fine if I compile the code with netcoreapp1.1

Ok, thanks for the confirmation. Hopefully we can move soon to netcore 2.0 and leave behind all these holes in the API and crazy references 馃槃

I think I found the problem ... and its a really weird one.

dotnet build resolves System.Runtime to a nuget package:

-r:/Users/kdummann/.nuget/packages/system.runtime/4.3.0/ref/netstandard1.5/System.Runtime.dll

But we resolve it to:

/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.5/System.Runtime.dll

Which is strange assembly only containing some basic subset of the original. The actual uri types are located in

/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.5/System.Private.Uri.dll

I was able to make the code compile by adding:

yield "-r:" + resolve "System.Private.Uri"

to the ProjectCracker but I don't know if this is the right way to fix it.

Wow, now that's funny. I just checked in dotnet 2.0 and the situation seems to be the same (there's a System.Private.Uri.dll in the NETCore.App folder). So I guess we may need to add the reference if we want to support Uris. That... or we finally do a proper .fsproj file resolution using MSBuild and @enricosada's library. But it seems the project system is still going to change for F# so maybe it's better to wait a bit more. Any thoughts on this @ncave?

For now, could you please PR your solution? Or better yet, your solution together with actual Uri support in Fable :wink: Cheers!

@alfonsogarciacaro @coolya Sure, whatever references are needed should be added. The only thing I would change is to make it compatible with more framework targets, i.e. instead of referencing the private assembly directly (which we're not supposedly supposed to do), you can reference the assembly it's in (which may or may not be the same private assembly) and put it in the netcore section.

Something like that:

let sysCoreLib = typeof<System.Object>.GetTypeInfo().Assembly.Location
let sysUriLib = typeof<System.Uri>.GetTypeInfo().Assembly.Location
...
        yield "--targetprofile:netcore"
        yield "-r:" + sysCoreLib // "CoreLib"
        yield "-r:" + sysUriLib // "System.Private.Uri"

or we finally do a proper .fsproj file resolution using MSBuild and @enricosada's library. But it seems the project system is still going to change for F# so maybe it's better to wait a bit more

project system isnt changing.
the same integration works for both sdk1.0 and sdk2.0 the same, because is based on msbuild, not special for f#. lots of things works the same for c# too 馃槃
So if you want to, just ping me, we can work together.
atm is just two files btw (or one file and a dll)

this works if project target multiple framework, you can get props, p2p, etc..

@coolya @ncave Great, thank you both for your help!

@enricosada Understood, thanks a lot for the pointers! I'll try to create a branch using dotnet-proj-info and see how it goes. I'll beg you for help as usual :wink:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MangelMaxime picture MangelMaxime  路  3Comments

rommsen picture rommsen  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

forki picture forki  路  3Comments

MangelMaxime picture MangelMaxime  路  3Comments