Skip to content

An error was thrown when use System.Reflection.Assembly.GetExecutingAssembly()  #132

Closed
@wuyu8512

Description

@wuyu8512

Hello

I'm trying dllexport for .NET Core
When I use System.Reflection.Assembly.GetExecutingAssembly (), it throws an exception

Unhandled exception. System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

Unhandled exception: System.IO.FileNotFoundException: Failed to load file or assembly "System.Runtime, Version = 4.2.2.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" or one of its dependencies. The system can not find the file specified.

v1.7beta3:
Manager: Tried both x86, x64 and Direct-Mod/Cecil and Rebase System Object in all possible variants.
Project type: .NET Core 3.1.100 Class Library

Code:

using System.Runtime.InteropServices;

namespace Test
{
	public static class Class1
	{
		[DllExport("AppInfo", CallingConvention = CallingConvention.StdCall)]
		public static string AppInfo()
		{
			string ApiVer = "9";             
			string AppID = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;  
			//string AppID = "Test";
			return string.Concat(ApiVer, ",", AppID);
		}
	}
}

Calling code

using System;
using System.Runtime.InteropServices;

namespace Console_Core
{
	class Program
	{
		[DllImport("Test.dll")]
		public static extern string AppInfo();

		static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");
			Console.WriteLine(AppInfo());
		}
	}
}

Thank you for your contribution to this project

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions