使用 Visual Studio 2022 社区 v 17.9.6 TragetFramework 8 项目文件的类库
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>.0
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>AchieveResource</AssemblyName>
<RootNamespace>Achieve.AchieveResource</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Achieve.Common">
<HintPath>..\Achieve.Common\bin\Debug\net8.0\Achieve.Common.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Update="AchieveResource1.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>AchieveResource1.resx</DependentUpon>
</Compile>
</ItemGroup>
</Project>
控制台应用程序正在引用此 dll,当调用其中一个静态方法时,它会抛出错误
FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified.
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Achieve.AchieveReserouce.ConnectionStrings' threw an exception.
Source=AchieveResource
StackTrace:
at Achieve.AchieveReserouce.ConnectionStrings.GetEnterpriseConnectionString()
at Program.<Main>$(String[] args) in C:\Dev\Achieve\2022Projects\ConsoleApp1\Program.cs:line 4
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5'. The system cannot find the file specified.
控制台应用程序中的行是
OUConstr = Achieve.AchieveReserouce.ConnectionStrings.GetConnectionSringForOU(1004);
我在引用 System.Data.SQLClient 4.8.6 之前尝试过,但遇到了类似的错误
Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.6.1.6, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
知道为什么会这样吗?谢谢
可能是由于项目没有正确引用或者找不到指定版本的程序集。根据您提供的信息,以下是一些建议: