Unable to get working using .NET 6
See original GitHub issue. . .
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?
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Visual Studio 2019 Not Showing .NET 6 Framework
To get Visual Studio 2019 to work with .NET 6 all you have to do is the following: Install the .NET 6 SDK:...
Read more >Unable to compile .net 6.0 projects in VS 2022
I am unable to compile .net 6.0 projects in VS 2022 (version 17.4.3). I see error message that - MSB3971 The reference assemblies...
Read more >Visual Studio 2019 unable to locate .Net Core SDK
Step 1) First run dotnet --list-sdks from the command line (as in Grzegorz Smulko's answer). Take note of the greatest version number.
Read more >.NET 6 core snowflake connector with External Browser ...
NET 6 core snowflake connector with External Browser Authentication failed with error. I am followed steps listed in below article.
Read more >Unable to locate the .NET SDK: The Reasons - Hamid Mosalla
Navigate to C:\Program Files\dotnet\sdk and see if you can find folders associated with different sdk versions. If you can't find any folder ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Shpendicus,
For example, .NET Core 2.2, or .NET Standard 2
Also note, lower version can be evaluated in higher Runtime. This is for the case when the module as an intermediary.
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 😃