-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Closed
Copy link
Description
Description
When call 'Type.GetType' after 'Assembly.LoadFrom', throw 'System.IO.FileLoadException'
Assembly assembly = Assembly.LoadFrom("Core.dll");
var type = Type.GetType("Foundation.NSObject, Xamarin.iOS");
Console.WriteLine("hello world");Crash:
Unhandled exception. System.IO.FileLoadException:
File name: 'Xamarin.iOS, Culture=neutral, PublicKeyToken=null'
---> System.ArgumentException: The path is empty. (Parameter 'path')
at System.IO.Path.GetFullPath(String path)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at Test.Program.Main(String[] args) in D:\Test\Test\Program.cs:line 12
Reproduction Steps
- Create .Net Standard 2.0 dll project, write something or nothing, compile
using System;
namespace Core
{
public class Class1
{
}
}- Create .Net 6 console project, code:
using System;
using System.IO;
using System.Reflection;
namespace Test
{
internal class Program
{
static void Main(string[] args)
{
Assembly assembly = Assembly.LoadFrom("Core.dll");
var type = Type.GetType("Foundation.NSObject, Xamarin.iOS");
Console.WriteLine("hello world");
}
}
}- Publish, using
.Net 6win-x64SingleFileSelfContained - Copy
Core.dlltoTest.exeroot directory - Run
Test.exe
Expected behavior
Output:
hello world
Actual behavior
Crash:
Unhandled exception. System.IO.FileLoadException:
File name: 'Xamarin.iOS, Culture=neutral, PublicKeyToken=null'
---> System.ArgumentException: The path is empty. (Parameter 'path')
at System.IO.Path.GetFullPath(String path)
at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName)
at Test.Program.Main(String[] args) in D:\Test\Test\Program.cs:line 12
Regression?
No response
Known Workarounds
This is not the solution!
If not used Assembly.LoadFrom everything ok.
// Assembly assembly = Assembly.LoadFrom("Core.dll");
var type = Type.GetType("Foundation.NSObject, Xamarin.iOS");
Console.WriteLine("hello world");Configuration
- .Net 6
- Windows / Linux
- x64
- Single File
pubxml:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0\publish\linux-x64\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>
</Project>Other information
No response
Reactions are currently unavailable