3F / DllExport

.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat)
MIT License
960 stars 133 forks source link

NetStandard 2.1 Demo Project x86 -- Could not load file or assembly 'netstandard, Version=2.1.0.0' #193

Open cmoski opened 3 years ago

cmoski commented 3 years ago

Hi all --

This may not be a bug, but I'm tearing my hair out trying to figure out where things are going wrong..

Sample Project here: https://github.com/cmoski/DllExportErrorExample

I'm getting a weird netstandard error that it cannot load the assembly when using a DateTime in the sample class -- can't quite figure out where this error is coming from.

Any assistance would be amazing!

Thanks.

Steps to reproduce:

  1. Create a NetStandard 2.1 DLL Library Project
  2. Create a C++ Native App to utilize DLL
  3. Call a C# Native function like DateTime

    public class Class1
    {
        [DllExport]
    
        static public double FailTest(double num1, double num2)
        {              
            return num1 - num2;              
        }
        public static DateTime Today = DateTime.Now; // <- If this variable init is commented out, the application works fine!
    }

Observe the error: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.

If the DateTime piece is commented out, app works fine. This is problematic for obvious reasons :P

Information from Data tab or log data:

Installed: True; 1.7.4+c1cc52f; invoked: 1.7.4
Project type: CsSdk
Storage: ProjectFiles
Compiler.Platform: Auto
Compiler.ordinalsBase: 1
Compiler.rSysObj: False
Compiler.ourILAsm: False
Compiler.customILAsm: 
Compiler.genExpLib: False
Compiler.peCheck: PeIl
Compiler.patches: None
PreProc.Type: None
PreProc.Cmd: 
PostProc.Type: None
PostProc.ProcEnv: $(SolutionPath);$(MSBuildThisFileFullPath)
PostProc.Cmd: 
SignAssembly: 
Identifier: D9901FE8-62AA-4BE4-96A4-8F48F6C83261
Instance: C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\MSBuild.exe
Project path: C:\Dev\SubmissionTo3F\SmallFuncTest\SmallFuncTest.csproj
Action: Configure
PlatformTarget: x86
TargetFramework: netstandard2.1
TargetFrameworks: 
TargetFrameworkVersion: 
RootNamespace: 
AssemblyName: 
MgrArgs: 
MetaLib: tools\raw\lib\net20\DllExport.dll
MetaCor: tools\raw\lib\netstd\DllExport.dll
Proxy: 
StoragePath: .net.dllexport.targets
ddNS: SmallFuncTest
ddNS max buffer: 500
UseCecil: True
intermediateFiles: False
timeout: 30000
Options: None
RootPath: C:\Dev\SubmissionTo3F\
PkgPath: C:\Dev\SubmissionTo3F\packages\\DllExport.1.7.4\
SlnFile: 
SlnDir: C:\Dev\SubmissionTo3F\
DxpTarget: tools\net.r_eg.DllExport.targets
MsgGuiLevel: -1
LockIfError: 

Demo Project file: https://github.com/cmoski/DllExportErrorExample

3F commented 3 years ago

Hello @cmoski Thanks for the report!

This is known behavior since I implemented rebasing only for system objects: https://github.com/3F/DllExport/issues/125#issuecomment-561245575

Today you can try up to netstandard2.0 or netcoreapp2.2 for .NET Core based projects, or netfx.

Higher versions can be implemented later. But no ETA, https://www.reddit.com/r/x3F/comments/ovq368/highspeed_multiplication_of_large_numbers_fast/

cmoski commented 3 years ago

@3F Thanks again for your contributions to open source, this project, and all your work. Very cool hashing function! I may have to use it in a project that I'm working on which uses a hash of an XML reply in a key/value store to reply responses.

Any idea how technically difficult it would be to make this happen or guidance on what changes would need to be made to get it working on NET5.0?

I have looked at the new UnmanagedExports attribute in NET5.0, but it doesn't seem to support the exact use case I'm looking for of allowing legacy applications which use LoadLibrary in C++ to consume NET5.0 components. The project DDNE seems to require the host application (https://github.com/AaronRobinsonMSFT/DNNE) to make additional calls to instantiate the .NET libraries, which isn't really something that works for the application either.

Thanks again for the reply.

3F commented 3 years ago

@3F Thanks again for your contributions to open source, this project, and all your work. Very cool hashing function! I may have to use it in a project that I'm working on which uses a hash of an XML reply in a key/value store to reply responses.

Thank you for your trust! And thanks for using!

Any idea how technically difficult it would be to make this happen or guidance on what changes would need to be made to get it working on NET5.0?

I think same things such it was for my rebasing for system objects. It was fast like the following,

  1. 26 Oct 2019 the first look at some way https://github.com/3F/DllExport/issues/90#issuecomment-546637702
  2. 28 Oct 2019 first draft PR https://github.com/3F/DllExport/pull/123
  3. 04 Nov 2019 first beta - to 21 Jan 2020 last beta;
  4. 31 Jan 2020 first stable release after all fixes and tests.

But it was then. Now, yes, https://twitter.com/github3F/status/1416067341759270915

I have looked at the new UnmanagedExports attribute in NET5.0, but it doesn't

You are not the first who contacts me with problems about the impossibility of something with their environments and the new unmanaged delegates in modern .NET 5. Because I usually recommend it primarily as a modern specification. However this seems not really cover all their needs at all o_O But in fact I'm not focused for this today and this hasn't been well played/tested yet by me to suggest something personally.

Support for this project, as well as my future, is very vague today. But more like I'll try in winter, maybe earlier, maybe later.