You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Null reference on Microsoft.Data.SqlClient.SqlClientFactory.Instance if loaded using Assembly.LoadFrom() in AppDomain.CurrentDomain.AssemblyResolve delegate #2064
when Microsoft.Data.SqlClient.dll (System.Data.SqlClient.dll the same) is resolved by following delegate dynamically at runtime, the Microsoft.Data.SqlClient.SqlClientFactory.Instance would be null.
While if not (such as reference as static nuget package at compile time), it works well.
AppDomain.CurrentDomain.AssemblyResolve += (sender, asm) =>
{
Assembly assembly = null;
//if (asm.Name.StartsWith("System.Data.SqlClient")) return Assembly.Load(asm.Name);
var dirs = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory).Concat(Directory.GetDirectories(Directory.GetCurrentDirectory())).ToList();
dirs.Insert(0, Directory.GetCurrentDirectory());
dirs.Insert(0, AppDomain.CurrentDomain.BaseDirectory);
foreach (var p in dirs.Select(i => Path.Combine(i, new AssemblyName(asm.Name).Name + ".dll")).Where(i => File.Exists(i)))
try
{
assembly = Assembly.LoadFrom(p);
if (asm.Name.StartsWith("Microsoft.Data.SqlClient"))
{
var type = assembly.GetType(new AssemblyName(asm.Name).Name + ".SqlClientFactory");
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);
var ci = type.GetProperties(BindingFlags.Static | BindingFlags.Public); // <-- ci == null here
}
break;
}
catch (Exception ex) { LogMan.Debug(ex.Message, ex); }
return assembly;
};
I found the problem only occurs if use own AssemblyResolver!! with the exception:
System.InvalidOperationException:“The requested .NET Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.”
In my project, i met the issue when System.Data.SqlClient is only loaded by my own plugin assembly loader, where the AppDomain.CurrentDomain.AssemblyResolve delegate is used to resolve missing assemblies .
If i reference Microsoft.Data.SqlClient directly as nuget package in my entry assembly, it works well. but not possible as in plugin.
I think there's something wrong in underlying assembly resolving process, when use own assembly resolver.
I replaced Microsoft.Data.SqlClient with System.Data.SqlClient, it's the same issue.
related issue: #1424 , this guy seemed to have used his own AssemblyResolver.
@xiaoyuvax. We investigated the issue and found that the custom assembly loader you provided is not loading the correct MDS dll.
When an app with a dependency on the MDS NuGet is build, the generated lib DLL gets copied to the bin folder. A runtimes folder is also copied there that contains all the different OS implementations. The assembly loader built into .NET will automatically load the correct DLL from the runtimes folder based on the running OS and CPU architecture.
Therefore, our suggestion is for you to enhance your custom assembly loader so that it also detects the running OS and CPU architecture and load the appropriate DLL from the runtimes folder.
@arellegue
i kinda get what u mean, but here r problems:
The custom assembly loader is not responsible for resolving native dlls in the /runtime/ folder.
It is up for the managed MDS dll to resolve its own native dependencies under P/Invoke rules, of which C# code is not in control.
If delete all SNI dlls in the /runtime/ folder for other platforms (in my case only win-x64 version left), this issue still exists. i.e. no way for MDS to select a wrong platform.
MDS doesn't have a custom assembly resolver. It lets .NET resolve the appropriate native Microsoft.Data.SqlClient.SNI.dll to load at runtime. How are you saying MDS is selecting the wrong DLL? Please be specific. Because it sounds like the only issues are in your custom assembly resolver.
Also, if you want to avoid the MDS native assemblies completely, you can try the AppContext switch UseManagedNetworkingOnWindows:
Add AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true); , the issue persists.
it seems the SNI.dll is not related.
have to reiterate: the custom resolver does NOT resolves NATIVE DLLs such as Microsoft.Data.SqlClient.SNI.dll anyway, which is NOT a managed assembly at all.
Ignore the native assembly issue. You aren't even getting that far. Your custom resolver is just loading the first M.D.S.dll it finds. This is incorrect. It is loading a DLL that doesn't have an implementation (by design). It needs to replicate the .NET assembly loader logic, which loads the correct OS-specific implementation DLL from a subfolder under runtimes based on the OS the process is running on.
@David-Engel i guess u didn't stepped in the resolver code urself, did u?
here let me detail on the test process, in which i could not identify any problem:
The plugin dll together with its dependencies r entirely output to the output path of the main program by the compiler, including the \runtimes\ folder.
Debugging the demo program, i can see only two assemblies r ever requested to my custom resolver:
above \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll, requested from System.Data.Common, Version=7.0.0.0 and is successfully loaded.
System.Data.Common.resources, also requested from System.Data.Common, Version=7.0.0.0 but not loaded and then ignored, because this resource file does not exist at all.
i don't think the 1st assembly r OS-specific, and it is the correct one to be loaded (despite maybe it has no implementation by design), yet no other assembly nor any assembly or even those under \runtimes\ folder is requested.
I guess:
the next step is for certain "Net assembly loader logic" to resolve dependencies for \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll , including those natives and managed assemblies under \runtimes\ folder according to OS. However, it never happened to the custom resolver, who never received any additional resolving request.
or there must be some ".NET assembly loader logic" that we don't know beyond the the custom resolver mechanism?
Another test:
I removed all other OS-specific files from \runtimes\ folder except for win-x64 on which i run the test so that no chance for any resolving mechanism to select a wrong OS-specific dll in the \runtimes\ folder.
i.e finally, only this sole file remains.
@David-Engel David Engel (Simba Technologies Inc) Vendor i guess u didn't stepped in the resolver code urself, did u?
I have, but I don't need to step into the code to see there clearly isn't any OS platform detection logic in it, which is your problem.
Your app is blindly loading the first DLL that passes your name match. THIS IS WRONG:
foreach (var p in dirs.Select(i => Path.Combine(i, new AssemblyName(asm.Name).Name + ".dll")).Where(i => File.Exists(i)))
try
{
assembly = Assembly.LoadFrom(p);
above \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll, requested from System.Data.Common, Version=7.0.0.0 and is successfully loaded.
Correction: Microsoft.Data.SqlClient, Culture=neutral, PublicKeyToken=null is requested. Not \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll. \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll is what you are INCORRECTLY loading.
System.Data.Common.resources, also requested from System.Data.Common, Version=7.0.0.0 but not loaded and then ignored, because this resource file does not exist at all.
i don't think the 1st assembly r OS-specific, and it is the correct one to be loaded (despite maybe it has no implementation by design), yet no other assembly nor any assembly or even those under \runtimes\ folder is requested.
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dll is not OS-specific. But it's not the one that your assembly resolver should be loading. When Micorosoft.Data.SqlClient is requested, your resolver should load \bin\Debug\net7.0\runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dll if running on unix (including linux/maxOS) or \bin\Debug\net7.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll if running on Windows. If the OS is neither unix nor Windows, then it should load \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll as the fallback, which throws (or should throw) a PlatformNotSupported exception for every API.
I guess:
the next step is for certain "Net assembly loader logic" to resolve dependencies for \bin\Debug\net7.0\Microsoft.Data.SqlClient.dll , including those natives and managed assemblies under \runtimes\ folder according to OS. However, it never happened to the custom resolver, who never received any additional resolving request.
or there must be some ".NET assembly loader logic" that we don't know beyond the the custom resolver mechanism?
As I said, \bin\Debug\net7.0\Microsoft.Data.SqlClient.dllshould not be loaded in your scenario.
Another test: I removed all other OS-specific files from \runtimes\ folder except for win-x64 on which i run the test so that no chance for any resolving mechanism to select a wrong OS-specific dll in the \runtimes\ folder. i.e finally, only this sole file remains.
That's wrong but you aren't even getting to the request to load the SNI DLL because you aren't loading the correct Microsoft.Data.SqlClient DLL. That's why I said to ignore the SNI DLL for now. You need to keep the \bin\Debug\net7.0\runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dll and \bin\Debug\net7.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll files as those are the ones your custom resolver should be loading based on the OS at runtime.
Once you've figured out OS platform-specific loading logic, these files should also remain (they all should remain, really, because they are OS-specific implementations of each library): \bin\Debug\net7.0\runtimes\win-arm\native\Microsoft.Data.SqlClient.SNI.dll \bin\Debug\net7.0\runtimes\win-arm64\native\Microsoft.Data.SqlClient.SNI.dll \bin\Debug\net7.0\runtimes\win-x64\native\Microsoft.Data.SqlClient.SNI.dll \bin\Debug\net7.0\runtimes\win-x86\native\Microsoft.Data.SqlClient.SNI.dll
As Microsoft.Data.SqlClient.SNI.dll is a dependency of Microsoft.Data.SqlClient.dll. When Microsoft.Data.SqlClient.SNI.dll is requested, your custom resolver should similarly load the correct Microsoft.Data.SqlClient.SNI.dll DLL based on the corresponding OS architecture at runtime. (Win arm32, Win arm64, Win x64, or Win x86)
This OS-platform-specific loading logic is not specific to SqlClient. This is how the .NET assembly resolver works for all libraries.
ah, thanks, now u gave the exact info that i need, as i've guessed:
...
or there must be some ".NET assembly loader logic" that we don't know ...?
If anybody had explained this loading logic in the first place, this issue would be solved earlier.
now I've changed my code (simply remove the \bin\Debug\net7.0\Microsoft.Data.SqlClient.dl and \unix\ subfolder), tested it and it works, BUT the custom resolver didn't resolve any SNI.dll at all, for as i've reiterated they are native dlls instead of managed assemblies and is not possibly been loaded by the custom resolver. Native dlls r resolved upon each call following some other mechanism concerning P/Invoke and is managed by OS somehow.
so following line of ur claim is not correct:
As Microsoft.Data.SqlClient.SNI.dll is a dependency of Microsoft.Data.SqlClient.dll. When Microsoft.Data.SqlClient.SNI.dll is requested, your custom resolver should similarly load the correct Microsoft.Data.SqlClient.SNI.dll DLL based on the corresponding OS architecture at runtime. (Win arm32, Win arm64, Win x64, or Win x86)
We've explained it multiple times. MDS doesn't load any of the assemblies itself. Nor does it call P/Invoke directly for the native SNI DLL. It uses DllImport attributes on extern references and lets .NET choose the DLL. Your custom assembly loader is the problem.
I am also facing similar issue, I build my project as class library with AnyCPU and that library is loaded dynamically at runtime as a plugin. My class library is referring to MDS library. I was facing System.PlatformNotSupportedException: 'Microsoft.Data.SqlClient is not supported on this platform.' exception
After reading:
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dll is not OS-specific. But it's not the one that your assembly resolver should be loading. When Micorosoft.Data.SqlClient is requested, your resolver should load \bin\Debug\net7.0\runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dll if running on unix (including linux/maxOS) or \bin\Debug\net7.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dll if running on Windows.
I modified my code to load OS-specific dll like this:
This solved the PlatformNotSupportedException, though on conn.Open() I am getting exception as:
System.TypeInitializationException: 'The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.'
It has inner exception as:
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
I can see the System.Configuration.ConfigurationManager.dll is present exactly parallel to my class library dll or in the same directory where non-os-specific Microsoft.Data.SqlClient.dll is present.
@JRahnama Yes the OS-specific Microsoft.Data.SqlClient.dll file is loaded from runtimes folder. In the code shared above dbExtensionPath variable contains path till runtimes folder. For rg. <project_directory>bin\Debug\net6.0\extensions\runtimes.
<project_directory>bin\Debug\net6.0\ folder contain the executing .exe which loads extension dll (which is my class library) dynamically from "extensions" folder.
You need to use NativeLibrary.TryLoad() to manually load the corresponding native library namely xxx.sni.dll. as i've re-reiterated many many times above, since AppDomain.CurrentDomain.AssemblyResolve does not resolve native libs at all.
Thanks @xiaoyuvax for that gist, though I have one question, it's clear that for managed dependencies you are resolving using AssemblyResolve() but how you are triggering the loading of UN-managed native dependency because AssemblyResolve() is not triggering for SNI.dll files.
Is it fine to load native libraries by using NativeLibrary.SetDllImportResolver()?
Thanks @xiaoyuvax for that gist, though I have one question, it's clear that for managed dependencies you are resolving using AssemblyResolve() but how you are triggering the loading of UN-managed native dependency because AssemblyResolve() is not triggering for SNI.dll files.
it doesn't matter if it is triggered, nor even when it is loaded, it will work as long as the sni.dll is loaded anytime before the Microsoft.Data.SqlClient.dll is loaded, and it will be kept in memory waiting to serve. so do the unmanged loading anytime before loading the managed assembly is just ok.
according to my understanding, NativeLibrary.SetDllImportResolver() may affect loading of other dlls, i don't think it's proper.
load ur specific dll and make it work , that's just neatly enough.
Activity
Kaur-Parminder commentedon Jun 16, 2023
@xiaoyuvax Can you provide standalone application repro of the issue?
xiaoyuvax commentedon Jun 19, 2023
https://github.com/xiaoyuvax/SqlClient.InstanceNullDemo.git @Kaur-Parminder
JRahnama commentedon Jun 22, 2023
It could also be helpful if looking at probably related issues at #426, #1714, #1424
arellegue commentedon Jun 26, 2023
@xiaoyuvax. We investigated the issue and found that the custom assembly loader you provided is not loading the correct MDS dll.
When an app with a dependency on the MDS NuGet is build, the generated lib DLL gets copied to the bin folder. A runtimes folder is also copied there that contains all the different OS implementations. The assembly loader built into .NET will automatically load the correct DLL from the runtimes folder based on the running OS and CPU architecture.
Therefore, our suggestion is for you to enhance your custom assembly loader so that it also detects the running OS and CPU architecture and load the appropriate DLL from the runtimes folder.
xiaoyuvax commentedon Jun 27, 2023
@arellegue
i kinda get what u mean, but here r problems:
David-Engel commentedon Jun 27, 2023
MDS doesn't have a custom assembly resolver. It lets .NET resolve the appropriate native Microsoft.Data.SqlClient.SNI.dll to load at runtime. How are you saying MDS is selecting the wrong DLL? Please be specific. Because it sounds like the only issues are in your custom assembly resolver.
Also, if you want to avoid the MDS native assemblies completely, you can try the AppContext switch UseManagedNetworkingOnWindows:
xiaoyuvax commentedon Jun 28, 2023
I did the test:
Add
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true);, the issue persists.it seems the SNI.dll is not related.
have to reiterate: the custom resolver does NOT resolves NATIVE DLLs such as Microsoft.Data.SqlClient.SNI.dll anyway, which is NOT a managed assembly at all.
David-Engel commentedon Jul 5, 2023
Ignore the native assembly issue. You aren't even getting that far. Your custom resolver is just loading the first M.D.S.dll it finds. This is incorrect. It is loading a DLL that doesn't have an implementation (by design). It needs to replicate the .NET assembly loader logic, which loads the correct OS-specific implementation DLL from a subfolder under runtimes based on the OS the process is running on.
xiaoyuvax commentedon Jul 10, 2023
@David-Engel i guess u didn't stepped in the resolver code urself, did u?
here let me detail on the test process, in which i could not identify any problem:
The plugin dll together with its dependencies r entirely output to the output path of the main program by the compiler, including the
\runtimes\folder.and the complete content of
\runtimes\folder:besides, notably there also exists:
Debugging the demo program, i can see only two assemblies r ever requested to my custom resolver:
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dll, requested from System.Data.Common, Version=7.0.0.0 and is successfully loaded.System.Data.Common.resources, also requested from System.Data.Common, Version=7.0.0.0 but not loaded and then ignored, because this resource file does not exist at all.i don't think the 1st assembly r OS-specific, and it is the correct one to be loaded (despite maybe it has no implementation by design), yet no other assembly nor any assembly or even those under
\runtimes\folder is requested.I guess:
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dll, including those natives and managed assemblies under\runtimes\folder according to OS. However, it never happened to the custom resolver, who never received any additional resolving request.Another test:
I removed all other OS-specific files from
\runtimes\folder except for win-x64 on which i run the test so that no chance for any resolving mechanism to select a wrong OS-specific dll in the\runtimes\folder.i.e finally, only this sole file remains.
the issue's still there.
David-Engel commentedon Jul 10, 2023
I have, but I don't need to step into the code to see there clearly isn't any OS platform detection logic in it, which is your problem.
Your app is blindly loading the first DLL that passes your name match. THIS IS WRONG:
Correction:
Microsoft.Data.SqlClient, Culture=neutral, PublicKeyToken=nullis requested. Not\bin\Debug\net7.0\Microsoft.Data.SqlClient.dll.\bin\Debug\net7.0\Microsoft.Data.SqlClient.dllis what you are INCORRECTLY loading.\bin\Debug\net7.0\Microsoft.Data.SqlClient.dllis not OS-specific. But it's not the one that your assembly resolver should be loading. WhenMicorosoft.Data.SqlClientis requested, your resolver should load\bin\Debug\net7.0\runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dllif running on unix (including linux/maxOS) or\bin\Debug\net7.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dllif running on Windows. If the OS is neither unix nor Windows, then it should load\bin\Debug\net7.0\Microsoft.Data.SqlClient.dllas the fallback, which throws (or should throw) a PlatformNotSupported exception for every API.As I said,
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dllshould not be loaded in your scenario.That's wrong but you aren't even getting to the request to load the SNI DLL because you aren't loading the correct Microsoft.Data.SqlClient DLL. That's why I said to ignore the SNI DLL for now. You need to keep the
\bin\Debug\net7.0\runtimes\unix\lib\net6.0\Microsoft.Data.SqlClient.dlland\bin\Debug\net7.0\runtimes\win\lib\net6.0\Microsoft.Data.SqlClient.dllfiles as those are the ones your custom resolver should be loading based on the OS at runtime.Once you've figured out OS platform-specific loading logic, these files should also remain (they all should remain, really, because they are OS-specific implementations of each library):
\bin\Debug\net7.0\runtimes\win-arm\native\Microsoft.Data.SqlClient.SNI.dll\bin\Debug\net7.0\runtimes\win-arm64\native\Microsoft.Data.SqlClient.SNI.dll\bin\Debug\net7.0\runtimes\win-x64\native\Microsoft.Data.SqlClient.SNI.dll\bin\Debug\net7.0\runtimes\win-x86\native\Microsoft.Data.SqlClient.SNI.dllAs
Microsoft.Data.SqlClient.SNI.dllis a dependency ofMicrosoft.Data.SqlClient.dll. WhenMicrosoft.Data.SqlClient.SNI.dllis requested, your custom resolver should similarly load the correctMicrosoft.Data.SqlClient.SNI.dllDLL based on the corresponding OS architecture at runtime. (Win arm32, Win arm64, Win x64, or Win x86)This OS-platform-specific loading logic is not specific to SqlClient. This is how the .NET assembly resolver works for all libraries.
xiaoyuvax commentedon Jul 12, 2023
ah, thanks, now u gave the exact info that i need, as i've guessed:
If anybody had explained this loading logic in the first place, this issue would be solved earlier.
now I've changed my code (simply remove the
\bin\Debug\net7.0\Microsoft.Data.SqlClient.dland\unix\subfolder), tested it and it works, BUT the custom resolver didn't resolve any SNI.dll at all, for as i've reiterated they are native dlls instead of managed assemblies and is not possibly been loaded by the custom resolver. Native dlls r resolved upon each call following some other mechanism concerning P/Invoke and is managed by OS somehow.so following line of ur claim is not correct:
David-Engel commentedon Jul 13, 2023
We've explained it multiple times. MDS doesn't load any of the assemblies itself. Nor does it call P/Invoke directly for the native SNI DLL. It uses DllImport attributes on extern references and lets .NET choose the DLL. Your custom assembly loader is the problem.
rover886 commentedon Jul 31, 2023
I am also facing similar issue, I build my project as class library with AnyCPU and that library is loaded dynamically at runtime as a plugin. My class library is referring to MDS library. I was facing
System.PlatformNotSupportedException: 'Microsoft.Data.SqlClient is not supported on this platform.'exceptionAfter reading:
I modified my code to load OS-specific dll like this:
This solved the PlatformNotSupportedException, though on
conn.Open()I am getting exception as:System.TypeInitializationException: 'The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.'It has inner exception as:
FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.I can see the System.Configuration.ConfigurationManager.dll is present exactly parallel to my class library dll or in the same directory where non-os-specific Microsoft.Data.SqlClient.dll is present.
What I am doing wrong here @David-Engel ? How did you solved your issue @xiaoyuvax ?
JRahnama commentedon Jul 31, 2023
@rover886 are the files loaded from runtime folder? If not can you set them to be loaded from runtime folder?
rover886 commentedon Jul 31, 2023
@JRahnama Yes the OS-specific Microsoft.Data.SqlClient.dll file is loaded from runtimes folder. In the code shared above
dbExtensionPathvariable contains path till runtimes folder. For rg. <project_directory>bin\Debug\net6.0\extensions\runtimes.<project_directory>bin\Debug\net6.0\ folder contain the executing .exe which loads extension dll (which is my class library) dynamically from "extensions" folder.
xiaoyuvax commentedon Aug 1, 2023
@rover886
You need to use NativeLibrary.TryLoad() to manually load the corresponding native library namely xxx.sni.dll. as i've re-reiterated many many times above, since AppDomain.CurrentDomain.AssemblyResolve does not resolve native libs at all.
I wrote a gist for my working universal solution, a method for both Managed and Unmanaged libs:
https://gist.github.com/xiaoyuvax/d2163faa3098bdf9ecb1adbc7458f1c5
rover886 commentedon Aug 1, 2023
Thanks @xiaoyuvax for that gist, though I have one question, it's clear that for managed dependencies you are resolving using
AssemblyResolve()but how you are triggering the loading of UN-managed native dependency becauseAssemblyResolve()is not triggering for SNI.dll files.Is it fine to load native libraries by using
NativeLibrary.SetDllImportResolver()?xiaoyuvax commentedon Aug 1, 2023
it doesn't matter if it is triggered, nor even when it is loaded, it will work as long as the sni.dll is loaded anytime before the Microsoft.Data.SqlClient.dll is loaded, and it will be kept in memory waiting to serve. so do the unmanged loading anytime before loading the managed assembly is just ok.
according to my understanding, NativeLibrary.SetDllImportResolver() may affect loading of other dlls, i don't think it's proper.
load ur specific dll and make it work , that's just neatly enough.