1

My code:

public string getLatestSysFileInDir(string directory) {
            
            string patt = "*sys-1*";
            var dirInfo = new DirectoryInfo(directory);
            var file = (from f in dirInfo.GetFiles(patt) orderby f.LastWriteTime descending select f).First();
            string name = file.Name;

            return name;
            }

The problem is with "LastWriteTime".

Full error message from compilation:

The type 'Func<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

Adding a netstandard.dll to References and compiling the project again generates a huge amount of errors from other files in the project including "Predefined System.Boolean is not defined or imported".

Why is this happening and what can I do to fix it?

(I changed the path to "MY_PROJ" before publishing it here.)

<ItemGroup>
    <Reference Include="GemBox.Spreadsheet, Version=43.0.35.1071, Culture=neutral, PublicKeyToken=b1b72c69714d4847">
      <HintPath>MY_PROJ\GemBox.Spreadsheet.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821">
      <HintPath>MY_PROJ\log4net.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="System">
      <Private>False</Private>
    </Reference>
    <Reference Include="Microsoft.Office.Interop.Excel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">`
      <HintPath>MY_PROJ\Microsoft.Office.Interop.Excel.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Core">
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Data">
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <HintPath>MY_PROJ\System.Data.DataSetExtensions.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Drawing">
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Windows.Forms">
      <Private>False</Private>
    </Reference>
    <Reference Include="System.Xml">
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Tasks" />
    <Folder Include="Tests" />
    <Folder Include="Properties\" />
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="Properties\ImportTypeMap.resx" />
  </ItemGroup>
annyka
  • 121
  • 6
  • Which dotnet version are you using or trying to use? – PMF Feb 17 '21 at 20:49
  • please add your csproj file if it is there. Also what sdks are installed on your machine? – Guru Stron Feb 17 '21 at 20:49
  • I'm using dotnet 3.5. – annyka Feb 17 '21 at 20:57
  • Does this answer your question? [You must add a reference to assembly 'netstandard, Version=2.0.0.0](https://stackoverflow.com/questions/49925484/you-must-add-a-reference-to-assembly-netstandard-version-2-0-0-0) – Peter B Feb 17 '21 at 21:24
  • Unfortunately, adding netstandard reference causes even more issues. I should note that yesterday my code compiled fine, this assembly error did not appear so it's something new. – annyka Feb 17 '21 at 21:33
  • The csproj posted above misses the top section. It may be relevant how the `` property looks like. – PMF Feb 18 '21 at 05:57
  • Can you update to .NET 4.8 or 5.0? 3.5 is not really compatibile with netstandard or .NET core, so if you have any (indirect) references to assemblies built for newer frameworks, that might not work. – PMF Feb 18 '21 at 06:02
  • My bad...TargetFrameworkVersion is v4.5 not 3.5. However, I cannot update it to a newer version. What I find odd is that my code worked a couple of days ago, I didn't downgrade the version. – annyka Feb 18 '21 at 07:06
  • 4.5 is also quite old already, so I'm not sure about compatibility. Normally, you would not need any `` tags any more in your project, but use `` instead. You'll probably have some indirect reference to a dependency that is not compatible with 4.5 in your project. – PMF Feb 18 '21 at 07:55

0 Answers0