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

FileNotFoundException for file: System.ComponentModel.TypeConverter.dll when used in TargetFramework .net7.0 with SelfContained set to true #706

Open
Kl-Li opened this issue May 19, 2023 · 2 comments

Comments

@Kl-Li
Copy link

Kl-Li commented May 19, 2023

Hello,
Allow me to start by saying thank you for this library.
I believe I have found an issue when migrating some code from .net6.0 to .net7.0.
If this is an issue on my end (eg wrong version etc please feel free to correct me)

Description:
Changing TargetFramework from net6.0 to net7.0 with SelfContained set to true seems to cause an Unhandled exception. of type: System.IO.FileNotFoundException. Looking at the directory I can see that the file is there but has a different version (please see attached picture).

Exception message:
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.ComponentModel.TypeConverter, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.ComponentModel.TypeConverter, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator() at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor) at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values) at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda[T,TResult](ParsingConfig parsingConfig, Boolean createParameterCtor, String expression, Object[] values)
at Program.Main(String[] args) in ...

Sample code:
Sample code can be found here: https://dotnetfiddle.net/wnh2gk

csproj configuration:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework> <!-- net6.0 -->
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>

    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained> <!-- false -->
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.2" />
  </ItemGroup>

</Project>

TargetFramework SelfContained Exception
net6.0 false No
net6.0 true No
net7.0 false No
net7.0 true Yes

image

@StefH
Copy link
Collaborator

StefH commented May 23, 2023

I think it's related to :

And I wonder if this can be solved in System.Linq.Dynamic.Core

Maybe you can create an issue for dotnet ?

@Kl-Li
Copy link
Author

Kl-Li commented May 26, 2023

Hello,
Yesterday I was able to spend some more time.
It seems the problem isn't related to the single executable as such but to the RID.
Below are my findings:

Running with :

    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>

The single executable found in the publish directory works as expected.
The issue appears if we run the "non single exe file". eg default debug inside the IDE

I also tried running with:

    <!-- <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained> -->
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>

and indeed the same issue appears (both in the debug and publish directory this time)

@StefH Due to the above i don't think it's related to the trimming. However from you links I noticed the below:
https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli#api-incompatibility

API Note
Assembly.Location Returns an empty string.

From a quick look at the code it seems that Assembly.Location is used (eg


Not sure if it's related (since those are APIs incompatibilities with single file deployment) but i thought it's worth mentioning.

I will try and do some more tests/reading and update accordingly.

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

No branches or pull requests

2 participants