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

System.NullReferenceException when user targets to .NET Standard 2.0 #177

Closed
Thorium opened this issue Nov 13, 2017 · 14 comments
Closed

System.NullReferenceException when user targets to .NET Standard 2.0 #177

Thorium opened this issue Nov 13, 2017 · 14 comments
Labels

Comments

@Thorium
Copy link
Member

Thorium commented Nov 13, 2017

When a .NET Standard 2.0 erasing type provider is used in a library project that targets .NET Standard 2.0, the ProvidedTypes.fs type ProvidedTypesContext method Create throws an exception in line:

    with e ->
        failwith (sprintf "Invalid host of cross-targeting type provider. Exception: %A" e)

...and it's a System.NullReferenceException:

Invalid host of cross-targeting type provider. Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at <StartupCode$FSharp-Data-SqlProvider>.$ProvidedTypes.referencedAssemblyPaths@8509.GenerateNext(IEnumerable`1& next)
   at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.MoveNextImpl()
      at Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1.System-Collections-IEnumerator-MoveNext()
	  at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
	  at ProviderImplementation.ProvidedTypes.ProvidedTypesContext.Create(TypeProviderConfig cfg, FSharpOption`1 assemblyReplacementMap)

.NET CoreApp 2.0 target seems to work ok.

@Thorium
Copy link
Member Author

Thorium commented Nov 13, 2017

The base is null:

let baseObj = tcImports.GetProperty("Base")

@Thorium
Copy link
Member Author

Thorium commented Nov 13, 2017

Just skipping the base object

    [ for dllInfo in dllInfos.GetElements() -> (dllInfo.GetProperty("FileName") :?> string)
      if baseObj <> null then
          for dllInfo in baseObj.GetProperty("Value").GetField("dllInfos").GetElements() -> (dllInfo.GetProperty("FileName") :?> string) 
    ]

...is not a working solution, the compiler will hang.

@dsyme
Copy link
Contributor

dsyme commented Nov 13, 2017

@Thorium Could you add a sample project that repros this? The test suite does have a sample of a .NET Standard 2.0 type provider (or it is in #175)

@Thorium
Copy link
Member Author

Thorium commented Nov 13, 2017

This might be ok, if ProvidedTypesContext Create is actually expired and not called anymore, I wasn't using the latest SDK version.
I was able to add netstandard2.0 to examples\ComboProvider.Tests.fsproj and it seems to build still.
<TargetFrameworks>netcoreapp2.0;net461;netstandard2.0</TargetFrameworks>

@Thorium
Copy link
Member Author

Thorium commented Nov 17, 2017

I tried to update to latest SDK but this still fails.

Branch is here https://github.com/fsprojects/SQLProvider/tree/sdk-update

  1. Run build.cmd to build the SQLProvider
  2. You may want to comment the try-catch from "Invalid host of cross-targeting type provider." from ProvidedTypes.fs
  3. Copy&overwrite SQLProvider\bin\netstandard2.0 content to your nuget cache e.g. C:\Users\myName.nuget\packages\SQLProvider\1.1.22\lib\netstandard2.0
  4. Try running build on one of the test projects, e.g. SQLProvider\tests\SqlProvider.Core.Tests

Now, the call to Create comes from constructor, which I tried to imitate from this projects examples\ComboProvider like this:

[<TypeProvider>]
type SqlTypeProvider(config: TypeProviderConfig) as this =     
    inherit TypeProviderForNamespaces(config, [("FSharp.Data.Sql", "FSharp.Data.Sql")])

@dsyme
Copy link
Contributor

dsyme commented Nov 28, 2017

Fixed by #179

@dsyme dsyme closed this as completed Nov 28, 2017
@Thorium
Copy link
Member Author

Thorium commented Nov 28, 2017

I'm not sure this is enough.
Let's see...

@Thorium
Copy link
Member Author

Thorium commented Nov 28, 2017

Yes, not fixed. Any ideas how could I go further? I think -v maybe fail to some other place than without it.

C:\git\SQLProvider\tests\SqlProvider.Core.Tests\MySql>dotnet build -v
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
   at System.SZArrayHelper.get_Item[T](Int32 index)
   at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index)
   at Microsoft.DotNet.Cli.Telemetry.TelemetryFilter.LogVerbosityForAllTopLevelCommand(ICollection`1 result, ParseResult parseResult, String topLevelCommandName)
   at Microsoft.DotNet.Cli.Telemetry.TelemetryFilter.Filter(Object objectToFilter)
   at Microsoft.DotNet.Cli.Utils.TelemetryEventEntry.SendFiltered(Object o)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

C:\git\SQLProvider\tests\SqlProvider.Core.Tests\MySql>dotnet run
C:\Program Files\dotnet\sdk\2.0.2\FSharp\Microsoft.FSharp.Targets(224,9): error MSB6006: "fsc.exe" exited with code -1073741571. [C:\git\SQLProvider\tests\SqlProvider.Core.Tests\MySql\SqlProvider.Core.Tests.fsproj]

The build failed. Please fix the build errors and run again.

C:\git\SQLProvider\tests\SqlProvider.Core.Tests\MySql>

@Thorium
Copy link
Member Author

Thorium commented Dec 4, 2017

I was hoping VS 15.5 would fix things, but no luck.
Same error.

Actually dotnet.exe build -v failure is "as designed", I had missing argument d. But after that:

       Using "Fsc" task from assembly "C:\Program Files\dotnet\sdk\2.1.2\FSharp\FSharp.Build.dll".
       Task "Fsc"
         C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\fsc.exe -o:obj\Debug\netstandard2.0\SqlProvider.Core.Tests.dll
         -g
         --debug:portable
         --noframework
         --define:TRACE
         --define:DEBUG
         --define:NETSTANDARD2_0
         --optimize-
         -r:C:\Users\tuoma\.nuget\packages\fsharp.core\4.2.3\lib\netstandard1.6\FSharp.Core.dll
         -r:C:\Users\tuoma\.nuget\packages\sqlprovider\1.1.22\lib\netstandard2.0\FSharp.Data.SqlProvider.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\Microsoft.Win32.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\mscorlib.dll
         -r:C:\Users\tuoma\.nuget\packages\mysqlconnector\0.29.0\lib\netstandard2.0\MySqlConnector.dll
         -r:C:\Users\tuoma\.nuget\packages\sqlprovider\1.1.22\lib\netstandard2.0\netstandard.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.AppContext.dll
         -r:C:\Users\tuoma\.nuget\packages\system.buffers\4.3.0\lib\netstandard1.1\System.Buffers.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Collections.Concurrent.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Collections.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Collections.NonGeneric.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Collections.Specialized.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ComponentModel.Composition.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ComponentModel.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ComponentModel.EventBasedAsync.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ComponentModel.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ComponentModel.TypeConverter.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Console.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Core.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Data.Common.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Data.dll
         -r:C:\Users\tuoma\.nuget\packages\system.data.sqlclient\4.4.0\ref\netstandard2.0\System.Data.SqlClient.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.Contracts.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.Debug.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.FileVersionInfo.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.Process.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.StackTrace.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.TextWriterTraceListener.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.Tools.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.TraceSource.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Diagnostics.Tracing.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Drawing.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Drawing.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Dynamic.Runtime.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Globalization.Calendars.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Globalization.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Globalization.Extensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.Compression.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.Compression.FileSystem.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.Compression.ZipFile.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.FileSystem.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.FileSystem.DriveInfo.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.FileSystem.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.FileSystem.Watcher.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.IsolatedStorage.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.MemoryMappedFiles.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.Pipes.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.IO.UnmanagedMemoryStream.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Linq.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Linq.Expressions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Linq.Parallel.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Linq.Queryable.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Http.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.NameResolution.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.NetworkInformation.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Ping.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Requests.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Security.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.Sockets.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.WebHeaderCollection.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.WebSockets.Client.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Net.WebSockets.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Numerics.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ObjectModel.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Reflection.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Reflection.Extensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Reflection.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\system.reflection.typeextensions\4.4.0\ref\netstandard2.0\System.Reflection.TypeExtensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Resources.Reader.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Resources.ResourceManager.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Resources.Writer.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.CompilerServices.VisualC.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Extensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Handles.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.InteropServices.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.InteropServices.RuntimeInformation.dll
         -r:C:\Users\tuoma\.nuget\packages\system.runtime.loader\4.3.0\ref\netstandard1.5\System.Runtime.Loader.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Numerics.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Serialization.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Serialization.Formatters.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Serialization.Json.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Serialization.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Runtime.Serialization.Xml.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Claims.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Cryptography.Algorithms.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Cryptography.Csp.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Cryptography.Encoding.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Cryptography.Primitives.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Cryptography.X509Certificates.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.Principal.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Security.SecureString.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ServiceModel.Web.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Text.Encoding.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Text.Encoding.Extensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Text.RegularExpressions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Overlapped.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Tasks.dll
         -r:C:\Users\tuoma\.nuget\packages\system.threading.tasks.extensions\4.3.0\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Tasks.Parallel.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Thread.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.ThreadPool.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Threading.Timer.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Transactions.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.ValueTuple.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Web.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Windows.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.Linq.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.ReaderWriter.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.Serialization.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.XDocument.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.XmlDocument.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.XmlSerializer.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.XPath.dll
         -r:C:\Users\tuoma\.nuget\packages\netstandard.library\2.0.0\build\netstandard2.0\ref\System.Xml.XPath.XDocument.dll
         --target:exe
         --warn:3
         --warnaserror:76
         --fullpaths
         --flaterrors
         --highentropyva-
         --targetprofile:netstandard
         --simpleresolution
         --nocopyfsharpcore
         C:\Users\tuoma\AppData\Local\Temp\.NETStandard,Version=v2.0.AssemblyAttributes.fs
         Program.fs

         Microsoft (R) F# Compiler version 4.1
         Copyright (c) Microsoft Corporation. All Rights Reserved.

         Process is terminated due to StackOverflowException.
  1:10>C:\Program Files\dotnet\sdk\2.1.2\FSharp\Microsoft.FSharp.Targets(263,9): error MSB6006: "fsc.exe" exited with code -1073741571. [C:\git\SQLProvider\tests\SqlProvider.Core.Tests\MySql\SqlProvider.Core.Tests.fsproj]
       Done executing task "Fsc" -- FAILED.
  1:10>Done building target "CoreCompile" in project "SqlProvider.Core.Tests.fsproj" -- FAILED.

@Thorium
Copy link
Member Author

Thorium commented Dec 5, 2017

I was thinking that the problem is this (ProvidedTypes.fs):

        let handler = ResolveEventHandler(fun _ args -> this.ResolveAssembly(args))
        do AppDomain.CurrentDomain.add_AssemblyResolve handler

//.... cut cut cut ...///

        default __.ResolveAssembly(args) =
            let expectedName = (AssemblyName(args.Name)).Name + ".dll"
            let expectedLocationOpt =
                probingFolders
                |> Seq.map (fun f -> Path.Combine(f, expectedName))
                |> Seq.tryFind File.Exists
            match expectedLocationOpt with
            | Some f -> Assembly.LoadFrom f
            | None -> null

...as clearly calling Assembly.LoadFrom inside ResolveEventHandler should lead to stack overflow exception as described here.

However, it seems that F# compiler manages to call the constructor, and also manages to call member __.GetNamespaces() of type TypeProviderForNamespaces but fails before calling member __.GetStaticParameters(ty). I don't have access to FSharp compiler pdb-files.

@vanceism7
Copy link

Hey @Thorium, any update on the state of this issue? I believe this is the same problem I've ran into when trying to use SQL provider

@Thorium
Copy link
Member Author

Thorium commented Jan 5, 2018

Yes, the latest version doesn't crash to a null-reference-exception but throws a stack-overflow-exception after a GetType-TryBindType-GetType-loop with "System.Object".

I made a fix in PR #183 but I expect we still have a problem here: In Linux environment with Core App the TypeProvider library is compiled with Mono and used with .NET Core on runtime. But there is a difference that "System.Object" is referenced from mscorlib.dll in Mono and netstandard.dll in Core.

After this PR what happens is that we get further in the compilation, but as the type-provider uses e.g. FSharp.Core, during the compilation it's loaded with reflection. Reflection tries to load all the dependency libraries, which are clear in .NET Framwork and .NET Core, but not with .NET Standard. In F# core there is e.g. alias bigint which is a dependency to Int64 loaded from which library: mscorlib.dll or netstandard.dll? Currently the build fails there.

Ping @dsyme, any architecture description help, or ideas for a workaround?

@Thorium
Copy link
Member Author

Thorium commented Jan 5, 2018

Added a PR that contains .NET Standard tests to demonstrate the problem.

@vanceism7
Copy link

Gotcha, so this is a .net standard issue then. Thanks for the info!

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

No branches or pull requests

3 participants