C# не видит system.web при тестирование метода на asp net
при вызове метода получаю такую ошибку:
System.TypeLoadException: "Could not load type 'System.Web.UI.WebControls.WebControl'
from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
В общем решение два проекта: 1 asp net (.net framework 4.6), 2 mstest (net 5.0) Код теста :
[TestMethod]
public void GetCompleted_byGuid()
{
//Тестовые данные
string testGuid = "A4A3770D-8202-45FB-B972-A4AE487C37F9";
//проверяем наличие КС
Completed_Work_MAIN mainTest = Completed_Work_MAIN.GetCompleted_byGuid(testGuid);
Assert.AreEqual(mainTest.user_in, "mstest");
Assert.AreEqual(mainTest.idm_object, 387);
Assert.AreEqual(mainTest.inn, 0);
}
Код метода:
public static Completed_Work_MAIN GetCompleted_byGuid(string guid)
{
var x = DB.DataSetSql<Completed_Work_MAIN>(SqlConnections.WorkflowConnection_Rengine,
"select * from View_Completed_Work_MAIN where guid = @guid",
new Fields() { { "@guid", guid } }).ToList();
if (x != null)
{
if (x.Count > 0)
{
return x[0];
}
}
return null;
}
DB - это (REngine.Database) Без теста все работает отлично, но если тестировать его из проекта теста , падает в ошибку Ссылка на asp net проект прокинута в тестовый , app.config сделать по примеру web, и тесты других методов с таким же подключением работают Пакеты подключенные к проекту тест:
app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="WorkflowProdConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="WorkflowConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="Base_DB_Connection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="ExternalConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
web.config:
<?xml version="1.0" encoding="utf-8"?>
<!--
Дополнительные сведения о настройке приложения ASP.NET см. на странице
https://go.microsoft.com/fwlink/?LinkId=169433.
-->
<configuration>
<configSections>
<sectionGroup name="devExpress">
<section name="themes" type="DevExpress.Web.ThemesConfigurationSection, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="compression" type="DevExpress.Web.CompressionConfigurationSection, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="settings" type="DevExpress.Web.SettingsConfigurationSection, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="errors" type="DevExpress.Web.ErrorsConfigurationSection, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
<section name="resources" type="DevExpress.Web.ResourcesConfigurationSection, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="WorkflowProdConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="ExternalConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="WorkflowConnection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
<add name="Base_DB_Connection" connectionString="Data Source=Source;Initial Catalog=Catalog;Persist Security Info=True;User ID=ID;Password=Password" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
Описание изменений web.config см. по адресу http://go.microsoft.com/fwlink/?LinkId=235367.
Следующие атрибуты можно установить с помощью тега <httpRuntime>.
<system.Web>
<httpRuntime targetFramework="4.6" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.6">
<assemblies>
<add assembly="DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
<add assembly="DevExpress.Data.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
<add assembly="System.Web.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="DevExpress.Printing.v19.2.Core, Version=19.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
<add assembly="DevExpress.Office.v19.2.Core, Version=19.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
<add assembly="DevExpress.RichEdit.v19.2.Core, Version=19.2.3.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A" />
<add assembly="DevExpress.Web.ASPxThemes.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
<add assembly="DevExpress.RichEdit.v19.2.Export, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.6" maxRequestLength="4096" requestValidationMode="4.0" executionTimeout="110" />
<pages validateRequest="true" clientIDMode="Static">
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
<add tagPrefix="dx" namespace="DevExpress.Web" assembly="DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
</controls>
</pages>
<httpModules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</httpModules>
<httpHandlers>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" validate="false" />
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" validate="false" />
</httpHandlers>
<globalization culture="ru" uiCulture="ru" />
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.webServer>
<modules>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add type="DevExpress.Web.ASPxHttpHandlerModule, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode" />
<add type="DevExpress.Web.ASPxUploadProgressHttpHandler, DevExpress.Web.v19.2, Version=19.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="ASPxUploadProgressHandlerPage.ashx" name="ASPxUploadProgressHandler" preCondition="integratedMode" />
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
<devExpress>
<themes enableThemesAssembly="true" styleSheetTheme="" theme="Glass" customThemeAssemblies="" baseColor="" font="" />
<compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true" />
<settings accessibilityCompliant="false" bootstrapMode="" doctypeMode="Html5" rightToLeft="false" checkReferencesToExternalScripts="true" protectControlState="true" ieCompatibilityVersion="edge" />
<errors callbackErrorRedirectUrl="" />
</devExpress>
<appSettings>
<add key="vs:EnableBrowserLink" value="false" />
</appSettings>
<system.codedom>
<compilers>
<compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.0 /nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\"Web\" /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</compilers>
</system.codedom>
</configuration>
.csproj(тестового проекта):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile></DocumentationFile>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<OutputPath></OutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Properties\**" />
<EmbeddedResource Remove="Properties\**" />
<None Remove="Properties\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.IO" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\тут путь\тут файл.csproj" />
</ItemGroup>
<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="app.config" DestinationFiles="$(OutDir)\testhost.dll.config" />
<Copy SourceFiles="app.config" DestinationFiles="$(OutDir)\testhost.x86.dll.config" />
</Target>
</Project>
Скрин ошибки:
Ответы (1 шт):
Проблема , как я понял была в том , что mstest использует NETCore.App, и это не подходит для (.net framework 4.6). Поэтому я просто перевел тесты с mstest на unittest под (.net framework 4.6), перенес все ссылки, и все заработало

