Re[3]: есть
От: Quebecois Канада https://www.canada.ca/
Дата: 26.11.22 16:28
Оценка:
Здравствуйте, Sinclair, Вы писали:

S>Простите, но вы неправы. Описанный вами сценарий и не должен работать, и не работает в С# независимо от наличия автоматически унаследованных конструкторов.

Работает.
  пруф
Минимальное репро — распакуется через patch -p1 < RefTest.patch:

diff -urN empty/ChildAssembly/ChildAssembly.csproj RefTest/ChildAssembly/ChildAssembly.csproj
--- empty/ChildAssembly/ChildAssembly.csproj    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ChildAssembly/ChildAssembly.csproj    2022-11-26 08:16:01.159127600 -0800
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ChildAssembly</RootNamespace>
+    <AssemblyName>ChildAssembly</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\ParentAssembly\ParentAssembly.csproj">
+      <Project>{1f74baf8-87a4-42d9-a148-d6e06e87c1d5}</Project>
+      <Name>ParentAssembly</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file
diff -urN empty/ChildAssembly/Class1.cs RefTest/ChildAssembly/Class1.cs
--- empty/ChildAssembly/Class1.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ChildAssembly/Class1.cs    2022-11-26 08:15:52.265586400 -0800
@@ -0,0 +1,17 @@
+using ParentAssembly;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ChildAssembly
+{
+    public class ChildClass : ParentClass
+    {
+        public ChildClass(int xyz)
+            : base(xyz)
+        {
+        }
+    }
+}
diff -urN empty/ChildAssembly/Properties/AssemblyInfo.cs RefTest/ChildAssembly/Properties/AssemblyInfo.cs
--- empty/ChildAssembly/Properties/AssemblyInfo.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ChildAssembly/Properties/AssemblyInfo.cs    2022-11-26 08:14:34.619592300 -0800
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ChildAssembly")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ChildAssembly")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("d75f07f9-ebf7-4e22-a5b8-56ce82b86b1b")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff -urN empty/ParentAssembly/Class1.cs RefTest/ParentAssembly/Class1.cs
--- empty/ParentAssembly/Class1.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ParentAssembly/Class1.cs    2022-11-26 08:15:28.472597700 -0800
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ParentAssembly
+{
+    public class ParentClass
+    {
+        public ParentClass(int xyz)
+        {
+        }
+    }
+}
diff -urN empty/ParentAssembly/ParentAssembly.csproj RefTest/ParentAssembly/ParentAssembly.csproj
--- empty/ParentAssembly/ParentAssembly.csproj    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ParentAssembly/ParentAssembly.csproj    2022-11-26 08:14:24.240936600 -0800
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>1f74baf8-87a4-42d9-a148-d6e06e87c1d5</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ParentAssembly</RootNamespace>
+    <AssemblyName>ParentAssembly</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System"/>
+    
+    <Reference Include="System.Core"/>
+    <Reference Include="System.Xml.Linq"/>
+    <Reference Include="System.Data.DataSetExtensions"/>
+    
+    
+    <Reference Include="Microsoft.CSharp"/>
+    
+    <Reference Include="System.Data"/>
+    
+    <Reference Include="System.Net.Http"/>
+    
+    <Reference Include="System.Xml"/>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ </Project>
diff -urN empty/ParentAssembly/Properties/AssemblyInfo.cs RefTest/ParentAssembly/Properties/AssemblyInfo.cs
--- empty/ParentAssembly/Properties/AssemblyInfo.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/ParentAssembly/Properties/AssemblyInfo.cs    2022-11-26 08:14:24.239935100 -0800
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ParentAssembly")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ParentAssembly")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("1f74baf8-87a4-42d9-a148-d6e06e87c1d5")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff -urN empty/RefTest.sln RefTest/RefTest.sln
--- empty/RefTest.sln    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/RefTest.sln    2022-11-26 08:16:01.162121500 -0800
@@ -0,0 +1,37 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.3.32901.215
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserAssembly", "UserAssembly\UserAssembly.csproj", "{F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParentAssembly", "ParentAssembly\ParentAssembly.csproj", "{1F74BAF8-87A4-42D9-A148-D6E06E87C1D5}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChildAssembly", "ChildAssembly\ChildAssembly.csproj", "{D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}"
+EndProject
+Global
+    GlobalSection(SolutionConfigurationPlatforms) = preSolution
+        Debug|Any CPU = Debug|Any CPU
+        Release|Any CPU = Release|Any CPU
+    EndGlobalSection
+    GlobalSection(ProjectConfigurationPlatforms) = postSolution
+        {F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+        {F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}.Debug|Any CPU.Build.0 = Debug|Any CPU
+        {F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}.Release|Any CPU.ActiveCfg = Release|Any CPU
+        {F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}.Release|Any CPU.Build.0 = Release|Any CPU
+        {1F74BAF8-87A4-42D9-A148-D6E06E87C1D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+        {1F74BAF8-87A4-42D9-A148-D6E06E87C1D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
+        {1F74BAF8-87A4-42D9-A148-D6E06E87C1D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
+        {1F74BAF8-87A4-42D9-A148-D6E06E87C1D5}.Release|Any CPU.Build.0 = Release|Any CPU
+        {D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+        {D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+        {D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+        {D75F07F9-EBF7-4E22-A5B8-56CE82B86B1B}.Release|Any CPU.Build.0 = Release|Any CPU
+    EndGlobalSection
+    GlobalSection(SolutionProperties) = preSolution
+        HideSolutionNode = FALSE
+    EndGlobalSection
+    GlobalSection(ExtensibilityGlobals) = postSolution
+        SolutionGuid = {8D059193-5B4D-4681-8237-6C1A7AAE8BCD}
+    EndGlobalSection
+EndGlobal
diff -urN empty/UserAssembly/App.config RefTest/UserAssembly/App.config
--- empty/UserAssembly/App.config    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/UserAssembly/App.config    2022-11-26 08:14:00.922848100 -0800
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+    </startup>
+</configuration>
\ No newline at end of file
diff -urN empty/UserAssembly/Program.cs RefTest/UserAssembly/Program.cs
--- empty/UserAssembly/Program.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/UserAssembly/Program.cs    2022-11-26 08:16:00.178966200 -0800
@@ -0,0 +1,17 @@
+using ChildAssembly;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UserAssembly
+{
+    internal class Program
+    {
+        static void Main(string[] args)
+        {
+            var cls = new ChildClass(123);
+        }
+    }
+}
diff -urN empty/UserAssembly/Properties/AssemblyInfo.cs RefTest/UserAssembly/Properties/AssemblyInfo.cs
--- empty/UserAssembly/Properties/AssemblyInfo.cs    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/UserAssembly/Properties/AssemblyInfo.cs    2022-11-26 08:14:01.067767700 -0800
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("UserAssembly")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("UserAssembly")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("f79c2c5c-777c-48fb-b8b3-54b0e73b8d27")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff -urN empty/UserAssembly/UserAssembly.csproj RefTest/UserAssembly/UserAssembly.csproj
--- empty/UserAssembly/UserAssembly.csproj    1969-12-31 16:00:00.000000000 -0800
+++ RefTest/UserAssembly/UserAssembly.csproj    2022-11-26 08:16:01.161121500 -0800
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{F79C2C5C-777C-48FB-B8B3-54B0E73B8D27}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>UserAssembly</RootNamespace>
+    <AssemblyName>UserAssembly</AssemblyName>
+    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\ChildAssembly\ChildAssembly.csproj">
+      <Project>{d75f07f9-ebf7-4e22-a5b8-56ce82b86b1b}</Project>
+      <Name>ChildAssembly</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>
\ No newline at end of file


UserAssembly создает экземпляр ChildClass без прямого reference на ParentAssembly. Т.е. на уровне метаданных достаточно вещей, вытянутых из ChildAssembly.

S>Корень проблемы, которую вы описываете в своём примере, не в том, что там что-то автоматически отнаследовалось, а в том, что владелец UserAssembly пытается использовать её без перекомпиляции после того, как одна из зависимостей (ChildAssembly) изменилась.

Я не говорю, что это хорошая user practice. Это просто пример того, что сейчас работает, и сломалось бы при добавлении наследования конструкторов.

S>Дотнет не рассчитан на такое использование. Правило большого пальца: если изменилась хотя бы одна из зависимостей, проект нужно пересобирать.

S>Исключения из этого правила очень редки, и требуют специальных усилий. Ну, там, к примеру, если вы пишете приложение, которое должно уметь работать с плагинами — в некотором смысле, плагины являются для вас зависимостями; но там вы будете прилагать специальные меры как со стороны приложения, так и со стороны плагинов (в виде набора ограничений на типы, экспортируемые из плагина) для предотвращения проблем с версионированием метаданных.
Я про плагины и говорил. Сейчас достаточно публичные интерфейсы вынести в отдельную assembly и не трогать существующие типы в ней. С наследованием это перестанет работать.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.