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

The type name 'SqlClientFactory' could not be found in the namespace 'System.Data.SqlClient' - Nuget references? #149

Open
dylanvdmerwe opened this issue Jan 2, 2023 · 2 comments

Comments

@dylanvdmerwe
Copy link

dylanvdmerwe commented Jan 2, 2023

I am trying to create a DbProviderFactory like this:

DbProviderFactory _factory = System.Data.SqlClient.SqlClientFactory.Instance;

However when running "t4 OrmLite.Poco.tt" from the command line, I get the following error:

OrmLite.Core.ttinclude(446,20): ERROR: The type name 'SqlClientFactory' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

Using t4 OrmLite.Poco.tt -r System.Data also does not work.

This is what I have included in a ttinclude file:

<#@ template language="C#" hostspecific="True" #>
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Data.Common" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>

My project file is relatively simple as well:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <None Remove=".gitignore" />
    <None Remove="OrmLite.Poco.tt" />
  </ItemGroup>

  <ItemGroup>
    <Content Include=".gitignore" />
    <Content Include="OrmLite.Poco.tt">
      <Generator>TextTemplatingFileGenerator</Generator>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
  </ItemGroup>

  <ItemGroup>
    <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
  </ItemGroup>

</Project>

It's like t4 is not picking up any nuget dependencies.

Any idea how to get this working so I can use a DbProviderFactory?

Other errors I get are all related to the System.Data.SqlClient (new SqlConnection()):

OrmLite.Core.ttinclude(756,30): ERROR: The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.

Everything works when running the tt file in VS. I need this tt file to work in VS as well as cross platform with this tool (like on linux).

@dylanvdmerwe dylanvdmerwe changed the title The type name 'SqlClientFactory' could not be found in the namespace 'System.Data.SqlClient' The type name 'SqlClientFactory' could not be found in the namespace 'System.Data.SqlClient' - Nuget references? Jan 2, 2023
@dylanvdmerwe
Copy link
Author

Note that doing an assembly reference like this more or less works, but surely should not be required:

<#@ assembly name="C:\Users\dylan\.nuget\packages\system.data.sqlclient\4.8.5\lib\netcoreapp2.1\System.Data.SqlClient.dll" #>

I still get a weird error, but I think that has to do with the dependency rather than this tool:

System.Data.SqlClient is not supported on this platform

@aschwartz-satcom
Copy link

My guess is it's doing something similar to the open source followup to System.Data.SqlClient, Microsoft.Data.SqlClient. See:

https://github.com/dotnet/SqlClient/wiki/Frequently-Asked-Questions#11-why-do-i-get-a-platformnotsupported-exception-when-my-application-hits-a-sqlclient-method

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

No branches or pull requests

2 participants