Type unification issues across different .NET profiles for type providers #99

Closed
KevinRansom opened this Issue Jan 25, 2015 · 7 comments

Comments

Projects
None yet
7 participants
@KevinRansom
Contributor

KevinRansom commented Jan 25, 2015

Originally opened at CodePlex bylatkin

Originally logged on github here.

The immediate issue is that types used by generative type providers are not being unified properly with types used in portable class libraries, resulting in erroneous compile errors "Static linking may not use assembly that targets different profile."

Attached is a repro project which fails to build with error "Static linking may not use assembly that targets different profile". It requires a SQL DB named "Test" with the following table:

USE [Test]
GO

/****** Object:  Table [dbo].[TweetSharp_Tweet]    Script Date: 10-Jan-14 20:45:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TweetSharp_Tweet](
       [ID] [bigint] NOT NULL,
       [InReplyToScreenName] [nvarchar](2000) NULL,
       [InReplyToStatusId] [bigint] NULL,
       [InReplyToUserId] [bigint] NULL,
       [IsFavorited] [bit] NOT NULL,
       [IsPossiblySensitive] [bit] NULL,
       [IsTruncated] [bit] NOT NULL,
       [Language] [nvarchar](50) NULL,
       [Location] [nvarchar](2000) NULL,
       [Place] [nvarchar](2000) NULL,
       [RawSource] [nvarchar](max) NULL,
       [RetweetCount] [int] NULL,
       [RetweetedStatus] [nvarchar](2000) NULL,
       [Source] [nvarchar](2000) NULL,
       [Text] [nvarchar](2000) NULL,
       [TextAsHtml] [nvarchar](2000) NULL,
       [TextDecoded] [nvarchar](2000) NULL,
       [User_ID] [bigint] NULL,
       [User_FollowersCount] [bigint] NULL,
       [Users_RetweetCount] [bigint] NULL,
       [Author_ScreenName] [nvarchar](2000) NULL,
       [CreatedDate] [datetime] NOT NULL,
CONSTRAINT [PK_TweetSharp_Tweet] PRIMARY KEY CLUSTERED 
(
       [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

When "newrec" is from SqlDataConnection type provider, representing SQL table with CreatedDate column of type [datetime], and "twt" is from LinqToTwitter portable library, the following line causes static linking error:
newrec.CreatedDate <- twt.CreatedAt

Commenting out this line works around the problem. Adding back just the below line will cause repro again:

let foo = twt.CreatedAt

Commentary from Vlad: I’d say that current behavior is a very crude workaround for the fact that generated types obtained from type providers are not rescoped but rather merged as is. Consequences of this is hard to predict, a few that I’ve seen were crashes on the late stages of the codegen when compiler tried and failed to find matching mscorlib types in System.Runtime and vice versa.

File Attachement

@latkin latkin added the bug label Jan 25, 2015

@dmitry-a-morozov

This comment has been minimized.

Show comment
Hide comment
@dmitry-a-morozov

dmitry-a-morozov May 5, 2015

Is this going to be solved in v4?
I'm hitting this issue when I use xUnit.NET v2.

Is this going to be solved in v4?
I'm hitting this issue when I use xUnit.NET v2.

@dsyme dsyme changed the title from Type unification issues across different .NET profiles to Type unification issues across different .NET profiles for type providers May 9, 2015

@dsyme dsyme added the pri-2 label May 9, 2015

@KevinRansom KevinRansom removed the pri-2 label Dec 4, 2015

@CumpsD

This comment has been minimized.

Show comment
Hide comment
@CumpsD

CumpsD Jan 23, 2016

When you want to use Serilog and FSharp.Configuration (SharpYaml) together, you run into this as well

CumpsD commented Jan 23, 2016

When you want to use Serilog and FSharp.Configuration (SharpYaml) together, you run into this as well

@CumpsD

This comment has been minimized.

Show comment
Hide comment
@CumpsD

CumpsD Jan 23, 2016

Here is a minimal repro:

https://github.com/CumpsD/staticlinking-bug

Serilog is profile 259

FSharp.Configuration is a TP, uses SharpYaml, SharpYaml is profile 136

At a certain point, the compiler runs into https://github.com/CumpsD/staticlinking-bug/blob/master/src/bug/Bug.fs#L13 and tries to access .Properties which is an IReadOnlyDictionary, when it hits https://github.com/fsharp/fsharp/blob/master/src/fsharp/fsc.fs#L1673 the name is System.Runtime and isMscorlib is true causing it to blow up with Static linking may not use assembly that targets different profile.

CumpsD commented Jan 23, 2016

Here is a minimal repro:

https://github.com/CumpsD/staticlinking-bug

Serilog is profile 259

FSharp.Configuration is a TP, uses SharpYaml, SharpYaml is profile 136

At a certain point, the compiler runs into https://github.com/CumpsD/staticlinking-bug/blob/master/src/bug/Bug.fs#L13 and tries to access .Properties which is an IReadOnlyDictionary, when it hits https://github.com/fsharp/fsharp/blob/master/src/fsharp/fsc.fs#L1673 the name is System.Runtime and isMscorlib is true causing it to blow up with Static linking may not use assembly that targets different profile.

@dsyme

This comment has been minimized.

Show comment
Hide comment
@dsyme

dsyme Nov 14, 2016

Contributor

@CumpsD Many thanks for the minimal repro (long ago!). I've submitted a fix to this bug.

Contributor

dsyme commented Nov 14, 2016

@CumpsD Many thanks for the minimal repro (long ago!). I've submitted a fix to this bug.

@kurtschelfthout

This comment has been minimized.

Show comment
Hide comment
@kurtschelfthout

kurtschelfthout Dec 2, 2016

Contributor

Can we close this now? (for folks like me going over bugs trying to fix, would be nice to close things, thanks!)

Contributor

kurtschelfthout commented Dec 2, 2016

Can we close this now? (for folks like me going over bugs trying to fix, would be nice to close things, thanks!)

@dsyme

This comment has been minimized.

Show comment
Hide comment
@dsyme

dsyme Dec 3, 2016

Contributor

Yes

Contributor

dsyme commented Dec 3, 2016

Yes

@dsyme dsyme closed this Dec 3, 2016

@nosami nosami referenced this issue in fsharp/fsharp Feb 10, 2017

Closed

Remove restriction on static linking #665

@sergey-tihon

This comment has been minimized.

Show comment
Hide comment
@sergey-tihon

sergey-tihon Mar 27, 2017

Contributor

Am I right that if I still see this issue on AppVeyor
https://ci.appveyor.com/project/sergey-tihon/swaggerprovider/build/0.0.1.335#L391
the only solution it to use newer F# compiler (VS2017 image)?

and generative TP that want to support full .net and pcl (xamarin) should provide assemblies compiled for both frameworks, because pcl assemblies references from full .net may break compilation in VS2015 and lower?

Contributor

sergey-tihon commented Mar 27, 2017

Am I right that if I still see this issue on AppVeyor
https://ci.appveyor.com/project/sergey-tihon/swaggerprovider/build/0.0.1.335#L391
the only solution it to use newer F# compiler (VS2017 image)?

and generative TP that want to support full .net and pcl (xamarin) should provide assemblies compiled for both frameworks, because pcl assemblies references from full .net may break compilation in VS2015 and lower?

@sergey-tihon sergey-tihon referenced this issue in fsprojects/SwaggerProvider Mar 28, 2017

Open

Error when using with Xamarin #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment