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

.Net7 ReflectionTypeLoadException: Unable to load one or more of the requested types. #445

Open
michalciolek opened this issue Oct 18, 2023 · 1 comment
Labels
area:.NET Core .NET Core related issues

Comments

@michalciolek
Copy link

Obfuscar unnecessarily renames methods that are implemention of some external interface. I get an exception:

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'GetObjectData' in type 'A.e' from assembly 'X, Version=2.10.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

For example, I have TestSerializable which implements ISerializable from System.Runtime.dll

namespace Test
{
    public class TestSerializable : ISerializable
    {
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {

        }
    }
}

After obfuscation (without any error) I get:

  1. for .NET 7 (assembly X.dll)
[X]Test.TestSerializable -> [X]A.e
{
	[X]Test.TestSerializable::GetObjectData[2]( [System.Runtime]System.Runtime.Serialization.SerializationInfo, [System.Runtime]System.Runtime.Serialization.StreamingContext ) -> A

	[X]Test.TestSerializable::.ctor[0]( ) skipped:  special name
}

GetObjectData method should be skipped but is renamed to A!

  1. for .Net Framework (assembly X.exe)
[X]Test.TestSerializable -> [X]A.e
{

	[X]Test.TestSerializable::GetObjectData[2]( [mscorlib]System.Runtime.Serialization.SerializationInfo, [mscorlib]System.Runtime.Serialization.StreamingContext ) skipped:  external base class or interface
	[X]Test.TestSerializable::.ctor[0]( ) skipped:  special name
}

Renaming GetObjectData was skipped, OK.

To fix this I have added System.Runtime.dll path to AssemblySearchPath:

<AssemblySearchPath path="C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.12\ref\net7.0\" />
@lextm lextm added the area:.NET Core .NET Core related issues label Oct 18, 2023
@deerchao
Copy link

This is happending for me too.
Worked around this by chaging the class to public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:.NET Core .NET Core related issues
Projects
None yet
Development

No branches or pull requests

3 participants