Skip to content

System.IO.FileLoadException: Could not resolve assemble "System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" when using WTelegramClient with DllExport #247

@2x0c0v8b

Description

@2x0c0v8b

Steps to reproduce:

Create new class library project using .NET Framework 4.7.2
Run DllExport

Image

Then install WTelegramClient NuGet package.
Adding a simple method creating WTelegram.Client. It failed when running from either unmanaged either managed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace telebird_dll
{

    static public class A
    {
        static WTelegram.Client client;

        [DllExport(CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
        public static void init(IntPtr x)
        {
            //string cur = Marshal.PtrToStringUni(x);
            //if (cur != "")
            //    cur += "session.dat";
            client = new WTelegram.Client(17349, "344583e45741c457fe1862106095a5eb");
        }

        // ...
    }
}

When running from managed program (C++ CLR) got this error:

Необработанное исключение: System.IO.FileLoadException: Не удалось загрузить файл или сборку "System.Text.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" либо одну из их зависимостей. Найденное определение манифеста сборки не соответствует ссылке на сборку. (Исключение из HRESULT: 0x80131040)
   в WTelegram.Session.LoadOrCreate(Stream store, Byte[] rgbKey)
   в WTelegram.Client..ctor(Func`2 configProvider, Stream sessionStore)
   в WTelegram.Client..ctor(Int32 apiID, String apiHash, String sessionPathname)
   в telebird_dll.A.init(IntPtr x) в C:\Users\Марк\source\repos\telebird\telebird_dll\Class1.cs:строка 21
   в main(String[] args) в C:\Users\Марк\source\repos\telebird\ConsoleApplication1\ConsoleApplication1.cpp:строка 7
   в mainCRTStartupStrArray(String[] arguments) в D:\a\_work\1\s\src\vctools\crt\crtw32\msilcrt\mcrtexe.cpp:строка 247

If just export this function without DllExport and run in managed code it run successful.

  • DllExport -version: 1.8.0.17264+f4deb0e
  • Used Visual Studio / MSBuild / ...: Visual Studio 2022

Information from Data tab or log data:

Installed: True; 1.8.0.17264+f4deb0e; invoked: 1.8.0
Project type: Cs
Storage: ProjectFiles
Compiler.Platform: Auto
Compiler.imageBase: 
Compiler.imageBaseStep: 
Compiler.ordinalsBase: 1
Compiler.rSysObj: False
Compiler.ourILAsm: True
Compiler.customILAsm: 
Compiler.genExpLib: False
Compiler.peCheck: PeIl, Pe32orPlus
Compiler.patches: None
Compiler.refreshObj: False
PreProc.Type: None
PreProc.Cmd: 
PostProc.Type: None
PostProc.ProcEnv: $(SolutionPath);$(MSBuildThisFileFullPath)
PostProc.Cmd: 
AssemblyExternDirectives: 
TypeRefDirectives: 
TypeRefOptions: None
RefPackages: 
SignAssembly(Debug): 
PlatformTarget(Debug): 
TargetFramework(Debug): 
TargetFrameworks(Debug): 
TargetFrameworkVersion(Debug): v4.7.2
TargetFrameworkIdentifier(Debug): 
RootNamespace(Debug): telebird_dll
AssemblyName(Debug): telebird_dll
DebugType(Debug): full
Optimize(Debug): false
DebugSymbols(Debug): true
SignAssembly(Release): 
PlatformTarget(Release): 
TargetFramework(Release): 
TargetFrameworks(Release): 
TargetFrameworkVersion(Release): v4.7.2
TargetFrameworkIdentifier(Release): 
RootNamespace(Release): telebird_dll
AssemblyName(Release): telebird_dll
DebugType(Release): pdbonly
Optimize(Release): true
DebugSymbols(Release): 
Identifier: ADFB7443-CE6A-4BCC-8ACD-14834702420F
Instance: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe
Project path: C:\Users\Марк\source\repos\telebird\telebird_dll\telebird_dll.csproj
Action: Configure
MgrArgs: 
MetaLib: tools\raw\lib\net20\DllExport.dll
MetaCor: tools\raw\lib\netstd\DllExport.dll
Proxy: 
StoragePath: .net.dllexport.targets
ddNS: System.Runtime.InteropServices
ddNS max buffer: 500
UseCecil: False
intermediateFiles: False
timeout: 30000
Options: None
RootPath: C:\Users\Марк\source\repos\telebird\
PkgPath: C:\Users\Марк\source\repos\telebird\packages\\DllExport.1.8.0\
SlnFile: 
SlnDir: C:\Users\Марк\source\repos\telebird\
DxpTarget: tools\net.r_eg.DllExport.targets
MsgLevel: Debug
MsgGuiLevel: -1
LockIfError: 

. . . {attachment if log}

Demo Project files / Samples / etc.:

test.zip

ConsoleApplication1 - managed import from c++ clr
ConsoleApplication2 - unmanaged import using winapi
telebird_dll - failure dll

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions