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

Unable to get working using .NET 6 #197

Closed
DiskCrasher opened this issue Jan 7, 2022 · 8 comments
Closed

Unable to get working using .NET 6 #197

DiskCrasher opened this issue Jan 7, 2022 · 8 comments

Comments

@DiskCrasher
Copy link

. . .

The question is related to:

  • DllExport -version: v1.7.4.29858+c1cc52f
  • Copy-paste from Data tab:
Installed: True; 1.7.4+c1cc52f; invoked: 1.7.4
Project type: Cs
Storage: ProjectFiles
Compiler.Platform: x86
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: BAE5D459-7C5A-46D1-9FE6-CF553C60A438
Instance: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe
Project path: C:\Users\user\Documents\Visual Studio Projects\COMLibraryCore\COMLibraryCore\COMLibraryCore.csproj
Action: Configure
PlatformTarget: x86
TargetFramework: net6.0-windows
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: COMLibraryCore
ddNS max buffer: 500
UseCecil: True
intermediateFiles: False
timeout: 30000
Options: None
RootPath: C:\Users\user\Documents\Visual Studio Projects\COMLibraryCore\
PkgPath: C:\Users\user\Documents\Visual Studio Projects\COMLibraryCore\packages\\DllExport.1.7.4\
SlnFile: 
SlnDir: C:\Users\user\Documents\Visual Studio Projects\COMLibraryCore\
DxpTarget: tools\net.r_eg.DllExport.targets
MsgGuiLevel: -1
LockIfError: 

Goal: To call a C# library DLL from Access VBA.

I got the below code working using .NET Framework 4.8:

using System.Runtime.InteropServices;

namespace COMLibrary;

public interface IComClass1Interface
{
    string HelloWorld { get; }
    string Delme();
}

[ComVisible(true)]
public class ComClass1 : IComClass1Interface
{
    public string HelloWorld { get { return "From DLL: Hello, World!"; } }

    public string Delme() => "From DLL: Hello, World!";
}

static class UnmanagedExports
{
    [DllExport]
    [return: MarshalAs(UnmanagedType.IDispatch)]
    static object CreateDotNetObject()
    {
        return new ComClass1();
    }
}

And calling from VBA:

Public Declare Function CreateDotNetObject Lib "C:\Users\user\Documents\Visual Studio Projects\COMLibrary\COMLibrary\bin\Debug\COMLibrary.dll" () As Object

Public Sub test()

    Dim o
    Set o = CreateDotNetObject()
    MsgBox o.HelloWorld
    Set o = Nothing

End Sub

However, when I use the same code in a .NET 6 project MS Access crashes when the VBA call is made. I've tried changing several things with no success. Dependencies tool shows the same CreateDotNetObject entry point in the DLL file, so it's not that.

What do I need to do to get this working with .NET 6?

@3F
Copy link
Owner

3F commented Jan 7, 2022

@DiskCrasher, Thanks for the report!

Please follow the instructions from #193 (comment)

@DiskCrasher
Copy link
Author

@DiskCrasher, Thanks for the report!

Please follow the instructions from #193 (comment)

In other words, .NET 5/6 aren't yet supported.

@3F
Copy link
Owner

3F commented Jan 7, 2022

In other words, .NET 5/6 aren't yet supported.

Only through targeting via supported .NET Core TFMs at this day (most recent version is 1.7.4)

@CodingMadness
Copy link

Mate, sry if im stupid, but im kinda new to .NET and especially to their massive architectual changes of the entire environment^^

Would you mind, stating in short sentence: How you mean by targeting via .NET core?

@3F
Copy link
Owner

3F commented Jan 12, 2022

How you mean by targeting via .NET core?

@Shpendicus,

targeting via supported .NET Core TFMs

For example, .NET Core 2.2, or .NET Standard 2

<TargetFrameworks>netstandard2.0</TargetFrameworks>

Also note, lower version can be evaluated in higher Runtime. This is for the case when the module as an intermediary.

@CodingMadness
Copy link

@3F the thing is, i watched your 3 min tutorial, on how to use your DLLExport-attribute, and i did it step by step, it even builds! BUT: the moment you passed, in the video, the newly created .dll into the "CFF" viewer, u could see the address of the static function you defined in your class, but when I did it, the address window in the "Exported Object" folder, in the CFF-viewer, was empty :(

the thing is, I use features of .NET 6 and this wont work then, right?

@CodingMadness
Copy link

Btw, I have donated you a monthly-fee for your work as a thanks to such big work, since every time I wanted something like COM or hard low level it's a pain in the ass, if you are not yet that good of a programmer, so yea pls keep up the dev of "DllExport" and also "Corini" to be usable fully with .NET 6 , in that sense, that you can export a .NET object/function even when u make use of all what is in .NET 6 and C# 10 :)

@3F
Copy link
Owner

3F commented Jan 13, 2022

the address window in the "Exported Object" folder, in the CFF-viewer, was empty :(

It shouldn't be empty. Make sure you're looking at correct assembly (x64 or x86 folder if you're using both arch)

the thing is, I use features of .NET 6 and this wont work then, right?

Right.

  1. For the case when TFM where exported methods is .NET 6 and CLR inits Runtime assembly v6, See An error was thrown when use System.Reflection.Assembly.GetExecutingAssembly()  #132
  2. For the case when TFM is lowever, for example .NET Core 2.1
    1. ...and CLR inits Runtime assembly v2, it must be failed because it can't process types from higher v6 at least without loading it in domain, but domain already contain loaded v2 at the moment. So you can't for several reasons.
    2. Only higher Runtime version can process types from lower such v2 but this implies related initialization at a first CLR "activation".

I just answered the same on youtube and if it's not you (not sure because I had a 4 several absolutely the same requests :) to me yesterday from different place),

What about modern unmanaged delegates? In referenced issue above we're talking also something about it and I think this is a main reason to me set automatically much less priority for this project in my timeline today (etc. https://www.reddit.com/r/x3F/comments/ovq368/highspeed_multiplication_of_large_numbers_fast/ )

"Corini"

*Conari

Btw, I have donated you a monthly-fee for your work as a thanks to such big work

Thank you! it is really appreciated!!

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

No branches or pull requests

3 participants