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 in .net 6 #25

Open
mblumenauer opened this issue Mar 15, 2022 · 9 comments
Open

FileNotFoundException in .net 6 #25

mblumenauer opened this issue Mar 15, 2022 · 9 comments

Comments

@mblumenauer
Copy link

Hi!

I want to use SharpProj.NetTopologySuite and i included the SharpProj and SharpProj.NetTopologySuite Nuget Packages in my .net 6 Project.
At runtime i get System.IO.FileNotFoundException Could not load file or assembly 'SharpProj, Version=8.2001.128.0, Culture=neutral, PublicKeyToken=3a930e679d9a0873'.

What am i doing wrong?

@Cedev
Copy link

Cedev commented Sep 2, 2022

The file it can't find is ijwhost.dll.

@ladnet
Copy link

ladnet commented Dec 15, 2022

Hi!

Same problem describe by @mblumenauer System.IO.FileNotFoundException Could not load file or assembly but tested with higher version of SharpProj and SharpProj.NetTopologySuite (9.1000.192 ).

@Cedev did you find a solution to this problem ? Are you talking about the answer given in this stackoverflow thread ? https://stackoverflow.com/questions/72635141/c-sharp-net6-c-cli-nuget-package-fails

@rhuijben what you think about this https://iamsorush.com/posts/cpp-csharp-swig/ ?
it will be interessting to wrapper PROJ with SWIG for crossplatform build and with no dependencies with Visual Studio (BuildTools only for windows), don't you ?

@framlingham
Copy link

framlingham commented Jan 4, 2023

I tried to build a test WPF project with .NET 7 (and redid with .NET 5 as well) and I think hit the same issue (VS2022 Preview). I tried running with all four 9.* versions of your library in NuGet, and restarting VS a few times. Project zips attached.

.NET 7: LoadSharpProjIsolated.zip
.NET 5: LoadSharProjIsolated2.zip

Exception text:

System.Windows.Markup.XamlParseException: ''The invocation of the constructor on type 'LoadSharProjIsolated2.MainWindow' that matches the specified binding constraints threw an exception.' Line number '7' and line position '2'.'
Inner Exception
BadImageFormatException: Could not load file or assembly 'SharpProj, Version=9.1.183.0, Culture=neutral, PublicKeyToken=3a930e679d9a0873'. An attempt was made to load a program with an incorrect format.

I'd love to use your library when this is fixed!

Edit: To mention projects use WPF.

@yuhangch
Copy link

yuhangch commented Mar 3, 2023

It takes my 1h🤦‍♂️, I thought it was caused by other problems。

@COWI-MI
Copy link

COWI-MI commented Mar 15, 2023

I get the same error using .NET Core 7 running in a DevContainer using image mcr.microsoft.com/devcontainers/dotnet:0-7.0

Could not load file or assembly 'SharpProj, Version=9.2000.234.0, Culture=neutral, PublicKeyToken=3a930e679d9a0873

Does SharpProj work with linux?

I am new to .NET but I can see some win references.

From obj/project.assets.json

"SharpProj.Core/9.2000.234": {
        "type": "package",
        "compile": {
          "ref/netcoreapp/SharpProj.dll": {}
        },
        "runtimeTargets": {
          "runtimes/win-arm64/lib/netcoreapp/SharpProj.dll": {
            "assetType": "runtime",
            "rid": "win-arm64"
          },
          "runtimes/win-x64/lib/netcoreapp/SharpProj.dll": {
            "assetType": "runtime",
            "rid": "win-x64"
          },
          "runtimes/win-x86/lib/netcoreapp/SharpProj.dll": {
            "assetType": "runtime",
            "rid": "win-x86"
          }
        }
      }

@tomvanenckevort
Copy link

As mentioned before in this issue, it seems that ijwhost.dll is required for SharpProj.dll to work.
There is an issue logged that seems to argue that ijwhost.dll should be included in the NuGet package, but then there is also another open issue where other future fixes are discussed around this (but no recent activity).

For the time being I've managed to get round the issue by including the ijwhost.dll file in the project where I have installed SharpProj:

<ItemGroup>
  <Content Include="$(NetCoreTargetingPackRoot)\Microsoft.NETCore.App.Host.$(NETCoreSdkRuntimeIdentifier)\$(BundledNETCoreAppPackageVersion)\runtimes\$(NETCoreSdkRuntimeIdentifier)\native\ijwhost.dll" Link="ijwhost.dll">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemGroup>

That will ensure the DLL is copied to the bin folder on build and after that SharpProj works as expected.
Note: this is in .NET 7, but I assume it will work similarly in .NET 6

@gpwen
Copy link

gpwen commented Sep 2, 2023

Encountered the same issue when using C++/CLI assembly targeting .NET 6.0 in C# project. I tried the above solution suggested by @tomvanenckevort, but found ijwhost.dll was copied from a different version of .NET SDK, not that of the targeting .NET.

After some debugging and searching through SDK build files, I found enabling $(UseIJWHost) property in the consuming C# project worked, ijwhost.dll from correct version of SDK (.NET 6.0 in my case) would be copied. My consuming C# project is a multi-targeting one (.NET Framework and .NET 6.0), I tried something like this:

<PropertyGroup>
  <UseIJWHost Condition="'$(TargetFramework)' == 'net6.0'">true</UseIJWHost>
</PropertyGroup>

@donnyv
Copy link

donnyv commented Dec 11, 2023

With version 9.2001.250 Its not copying the SharpProj.dll file at all. Its in the project.assets.json file but doesn't copy the dll to the bin. I also tried the project file edits. Only the @tomvanenckevort answer worked to get the ljshost.dll file copied over.

I'm using .net 6 with VS2022.

@Swahhillie
Copy link

Swahhillie commented Apr 18, 2024

I can build my project with dotnet build. But dotnet run can't execute it because Debug\net8.0\runtimes\win-x64\lib\netcoreapp\SharpProj.dll is not found. I can execute it by running the exe directly. This means I can add the executable as a native application to my IDE and attach the debugger to the running process. It is inconvenient but it worked for development.

Unfortunately, when I tried to host the project the same problem pops up. IIS can't launch the project because SharpProj.dll is not found.

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

No branches or pull requests

10 participants