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

Fail to serialize: Type cannot be found: System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute #117

Closed
AArnott opened this issue Jan 13, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@AArnott
Copy link

AArnott commented Jan 13, 2020

I tried using this in StreamJsonRpc to dump out a dynamically written assembly.

https://github.com/AArnott/vs-streamjsonrpc/blob/c17313e3aed25059de03c3484882729e6c265dff/src/StreamJsonRpc/ProxyGeneration.cs#L362

It failed with the exception below:

Test Name:	JsonRpcProxyGenerationTests.CallMethod_IntInt_Int
Test FullName:	StreamJsonRpc.Tests (netcoreapp2.1).JsonRpcProxyGenerationTests.JsonRpcProxyGenerationTests.CallMethod_IntInt_Int
Test Source:	D:\git\streamjsonrpc\src\StreamJsonRpc.Tests\JsonRpcProxyGenerationTests.cs : line 166
Test Outcome:	Failed
Test Duration:	0:00:00

Test Name:	JsonRpcProxyGenerationTests.CallMethod_IntInt_Int
Test Outcome:	Failed
Result StackTrace:	
at Lokad.ILPack.Metadata.AssemblyMetadata.GetTypeHandle(Type type)
   at Lokad.ILPack.AssemblyGenerator.CreateCustomAttributes(EntityHandle parent, IEnumerable`1 attributes)
   at Lokad.ILPack.AssemblyGenerator.GenerateAssemblyBytes(Assembly assembly)
   at Lokad.ILPack.AssemblyGenerator.GenerateAssembly(Assembly assembly, String path)
   at StreamJsonRpc.ProxyGeneration.Get(TypeInfo serviceInterface) in D:\git\streamjsonrpc\src\StreamJsonRpc\ProxyGeneration.cs:line 362
   at StreamJsonRpc.JsonRpc.Attach[T](Stream sendingStream, Stream receivingStream) in D:\git\streamjsonrpc\src\StreamJsonRpc\JsonRpc.cs:line 573
   at StreamJsonRpc.JsonRpc.Attach[T](Stream stream) in D:\git\streamjsonrpc\src\StreamJsonRpc\JsonRpc.cs:line 556
   at JsonRpcProxyGenerationTests..ctor(ITestOutputHelper logger) in D:\git\streamjsonrpc\src\StreamJsonRpc.Tests\JsonRpcProxyGenerationTests.cs:line 30
Result Message:	
System.ArgumentException : Type cannot be found: "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute, rpcProxies_cdac9d9d-b20f-49ff-9b2d-330b04eb391c, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
Parameter name: type
@vermorel vermorel changed the title ArgumentException thrown while dumping assembly to disk Fail to serialize: Type cannot be found: "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute Jan 13, 2020
@vermorel vermorel changed the title Fail to serialize: Type cannot be found: "System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute Fail to serialize: Type cannot be found: System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute Jan 13, 2020
@vermorel vermorel added the bug Something isn't working label Jan 13, 2020
@ericstj
Copy link
Contributor

ericstj commented Nov 20, 2020

I was able to reproduce the same with this small repro:

using System;
using System.Reflection;

namespace proxy
{
    class Program
    {
        static void Main(string[] args)
        {
            TestType_IHelloService proxy = DispatchProxy.Create<TestType_IHelloService, TestDispatchProxy>();

            var assembly = Assembly.GetAssembly(proxy.GetType());
            Console.WriteLine(assembly);
            Console.WriteLine(assembly.GetType("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"));

            var generator = new Lokad.ILPack.AssemblyGenerator();
            generator.GenerateAssembly(assembly, assembly.GetName().Name + ".dll");
        }
    }

    internal interface TestType_IHelloService
    {
        string Hello(string message);
    }

    internal class TestDispatchProxy : DispatchProxy
    {
        protected override object Invoke(MethodInfo targetMethod, object[] args) => null;
    }
}

@ericstj
Copy link
Contributor

ericstj commented Nov 20, 2020

I have found the problem and will submit a PR to fix this. It looks like ILPack doesn't handle when a custom attribute is both defined in the assembly and applied to the assembly.

Also found a bug in DispatchProxy dotnet/runtime#45029

@vermorel
Copy link
Member

Should be fixed from 0.1.7+ onward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants