API Support Forum
OEC API > API Support > Error when i call GF.Api.Impl.GFApi.CreateClient()
Author Topic: Error when i call GF.Api.Impl.GFApi.CreateClient()
(11 messages, Page 1 of 1)
Moderators: VPfau
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 23, 2020 @ 09:54 AM             Msg. 1 of 11
Hi,

I am starting to use the new GFAPI. I am using Visual Basic .net as a development environment.

I get an error when I try to create the client using the method:

GF.Api.Impl.GFApi.CreateClient()

This is the error in detail:

A first chance exception of type 'System.MissingMethodException' occurred in GF.Api.Impl.dll

System.MissingMethodException occurred
HResult = -2146233069
Message = Method not found 'Void GF.SimpleInjector.InternalConstructorResolutionBehavior..ctor (SimpleInjector.Container)'.
Source = GF.Api.Impl
StackTrace:
in GF.Api.Impl.ApiCompositionRoot.Compose(Container container)
in GF.Api.Impl.ApiCompositionRoot.Compose()
in GF.Api.Impl.GFApi.CreateClient()
InnerException:


This error does NOT happen if I use your GF.AdvancedExample (c #) example.

Any suggestions?
Thank you.
Mauro frasson
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 24, 2020 @ 04:58 AM             Msg. 2 of 11
I have more information:
the issue occurs if I DO NOT insert your dll in the .exe file folder.

In my case, your DLLs are located from a different folder than the .exe and I load them dynamically using AppDomain.CurrentDomain.AssemblyResolve.
It seems that this loading type is not appropriate in your case. For what reason? Do your dlls load some internal dependency that is not found if the DLLs are in a different path than the .exe?
Mauro frasson
AMartzke
Posts: 13
Joined:


Posted: Jan 27, 2020 @ 07:37 AM             Msg. 3 of 11
How are you installing GFAPI? Are you using the Manage Nuget Packages for Solution window in Visual Studio? I installed GFAPI 4.0.3.16 in my solution using this method and was able to call GF.Api.Impl.GFApi.CreateClient() without errors.
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 27, 2020 @ 01:09 PM             Msg. 4 of 11
To reproduce the issue, try this "Visual Basic" console application:

Add the 4 GF.API dlls to the project references and set "Copy Local" = FALSE.
GF.Api.Values.dll
GF.Common.dll
GF.Api.dll
GF.Api.Impl.dll

Run 2 tests:

First Test:
1) Copy the 4 GF.API dlls in the folder "bin\Debug\dll\" (the DLLs will be loaded by AppDomain.CurrentDomain.AssemblyResolve)
2) Run -> error!

Second Test:
1) Copy the 4 GF.API dlls in the "bin\Debug\" folder -> the same as the .exe (DLLs will be loaded automatically)
2) Run -> OK!


This is the console app code:


Sub Main()
AddHandler AppDomain.CurrentDomain.AssemblyResolve, AddressOf MyResolveEventHandler

Main_Real()
End Sub


Public Sub Main_Real()
Dim GFclient As GF.Api.IGFClient = GF.Api.Impl.GFApi.CreateClient()
End Sub


Private Function MyResolveEventHandler(ByVal sender As Object, ByVal args As ResolveEventArgs) As System.Reflection.[Assembly]
Try
Dim DLL_Name As String = New System.Reflection.AssemblyName(args.Name).Name

If (String.IsNullOrWhiteSpace(DLL_Name) = False) Then
Dim Path As String = System.IO.Path.Combine(My.Application.Info.DirectoryPath, "dll")

Dim AssmbFullPath As String = System.IO.Path.Combine(Path, DLL_Name & ".dll")

If (System.IO.File.Exists(AssmbFullPath) = True) Then
Return System.Reflection.Assembly.LoadFrom(AssmbFullPath)
End If
End If
Catch ex As Exception
End Try

Return Nothing
End Function
Mauro frasson
AMartzke
Posts: 13
Joined:


Posted: Jan 28, 2020 @ 07:21 AM             Msg. 5 of 11
I was able to reproduce this problem using your steps. (It was not necessary for me to copy any DLLs.) This seems to only affect .NET Core applications. I will investigate the problem further.
AMartzke
Posts: 13
Joined:


Posted: Jan 28, 2020 @ 09:02 AM             Msg. 6 of 11
In your VB application, are you using .NET Framework or .NET Core? Currently, GFAPI does not support .NET Core.
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 28, 2020 @ 10:51 AM             Msg. 7 of 11
I use .NET Framework.

Other information:

The issue is that in the case of dynamic loading of DLLs, if they are not in the executable folder, loading does not find some of them. For example the SimpleInjector.dll and GF.SimpleInjector.dll and so on are not found. Basically all the DLLs embeded into GF.Api.Impl.dll are not found.

In fact, if instead of taking them from NuGet I take them from the "GAIN\Trader Dev 4.0" folder (all the DLLs contained in) and copy them into the bin/dll folder of the test console application, everything works.
In short, I need to physically have all the DLLs you use so that I can find and load them one by one. This solves the issue.

So my question is:
What exactly are all the DLLs you embed inside GF.Api.Impl.dll?
Mauro frasson

Edited by MFrasson3344 on Jan 28, 2020 10:53 AM
Edited by MFrasson3344 on Jan 28, 2020 10:54 AM
AMartzke
Posts: 13
Joined:


Posted: Jan 28, 2020 @ 12:11 PM             Msg. 8 of 11
It sounds like you are installing your Nuget package differently. You should not have to manually add any project references or copy any DLLs. Instead, use the Nuget tools inside Visual Studio:

1. In the Solution Explorer, right click the solution. Select Manage NuGet Packages for Solution.
2. In the Nuget window, click the Browse tab. Then search for GFAPI in the search bar.
3. Select GFAPI from the search results. On the right side, select all the .NET projects where you want to install this package. Then click Install.
4. In the Solution Explorer, check the References folder under your application. You should see the GFAPI project references.
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 28, 2020 @ 02:13 PM             Msg. 9 of 11
It's all right on my side. I added NuGet packages from the beginning exactly as you described.
I probably couldn't explain myself well.
I'll let you investigate using the test project above.

Please answer only this question for now:
What are the DLLs embedded in GF.Api.Impl.dll?

Thanks
Mauro frasson
AMartzke
Posts: 13
Joined:


Posted: Jan 30, 2020 @ 09:54 AM             Msg. 10 of 11
I believe these are the DLLs embedded in the GF.Api.Impl DLL in the GF.API NuGet package. Also, a Nuget package is a ZIP file, so you can view the contents by changing the extension to .zip and viewing it as a ZIP file.

GF.Api.Internal
GF.Api.Msgs
GF.Api.Msgs.Order.Admin
GF.Api.Msgs.Order
GF.Api.Msgs.Price
GF.Collections
GF.Domain.Common
GF.Domain.FuturesPairer
GF.Domain.Options.Greeks
GF.Net
GF.ProtoSharp
GF.SimpleInjector
LanguageExt.Core
SimpleInjector
System.ValueTuple
MFrasson3344
Posts: 41
Joined: Nov 09, 2015


Posted: Jan 31, 2020 @ 08:02 AM             Msg. 11 of 11
NuGet package contains only 4 DLLs:
GF.Api.dll
GF.Api.Impl.dll
GF.Api.Values.dll
GF.Common.dll

All others are embedded inside GF.Api.Impl.dll. This is my problem.
In my case, to load them dynamically from a different path than the executable folder, I need to have all DLLs (not embedded).

So I have 2 solutions:

Solution n. 1:
I put the 4 NuGet DLLs in the executable folder (not the best solution in my case);

Solution n. 2:
I insert all the DLLs (10+) in the folder where I want and dynamically load them.
Mauro frasson

Edited by MFrasson3344 on Jan 31, 2020 08:03 AM