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

ServiceJsonRpcDescriptor.JsonRpcConnection.ConstructRpcClient<T> fails to create an instance #789

Closed
Tracked by #60803
tmat opened this issue Apr 18, 2022 · 4 comments · Fixed by #804
Closed
Tracked by #60803
Assignees
Labels
Milestone

Comments

@tmat
Copy link
Member

tmat commented Apr 18, 2022

When called with an interface that implements another interface like so TypeLoadException is thrown.

Assembly1:

internal class C
{
  internal interface ICallback : I
  {
  }
}

Assembly2:

[assembly: InternalsVisibleTo("Assembly1")]

internal interface I
{
   ValueTask<E> Get(D d, CancellationToken token);
}

internal class D
{
}

internal class E
{
}
Feature 'Convert tuple to struct refactoring' is currently unavailable due to an internal error. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Access is denied: 'D'.
       at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
       at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
       at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
       at StreamJsonRpc.ProxyGeneration.CreateParameterObjectType(ModuleBuilder moduleBuilder, ParameterInfo[] parameters)
       at StreamJsonRpc.ProxyGeneration.Get(TypeInfo serviceInterface)
       at StreamJsonRpc.JsonRpc.Attach[T](JsonRpcProxyOptions options)
       at Microsoft.ServiceHub.Framework.ServiceJsonRpcDescriptor.JsonRpcConnection.ConstructRpcClient[T]()
--- End of inner exception stack trace ---
       at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
       at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at Microsoft.ServiceHub.Framework.ServiceRpcDescriptor.RpcConnection.ConstructRpcClient(Type interfaceType)
@AArnott
Copy link
Member

AArnott commented May 6, 2022

Thanks for reporting. This is likely something we can fix.

@AArnott AArnott added the bug label May 6, 2022
@AArnott AArnott self-assigned this Jun 9, 2022
@AArnott
Copy link
Member

AArnott commented Jun 9, 2022

I can't repro this. Here is my attempt:
ConsoleApp3.zip

Can you fix this up as necessary to repro and send back, @tmat?

@AArnott AArnott assigned tmat and unassigned AArnott Jun 9, 2022
@tmat
Copy link
Member Author

tmat commented Jun 10, 2022

Here: ClassLibrary1.zip
Forgot a parameter.

I looked more into the workaround we have in Roslyn and turns out, after some additional refactoring having this working won't save that much, so it's not that high of a priority to get fixed.

Thanks!

@AArnott
Copy link
Member

AArnott commented Jun 10, 2022

Bingo. I've got a test that repros the failure now. Thank you.
And thanks for the notice on reduced priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants