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

System.NotSupportedException when using Hot Reload (VS 2022 - .NET 6) #4789

Closed
mchlstrng opened this issue Feb 17, 2022 · 3 comments · Fixed by #4820
Closed

System.NotSupportedException when using Hot Reload (VS 2022 - .NET 6) #4789

mchlstrng opened this issue Feb 17, 2022 · 3 comments · Fixed by #4820
Assignees

Comments

@mchlstrng
Copy link
Contributor

mchlstrng commented Feb 17, 2022

VS feedback:
https://developercommunity.visualstudio.com/t/SystemNotSupportedException-when-using/1663264?space=8&q=wcf+hot+reload

I get a System.NotSupportedException when using Hot Reload in an ASP.NET Core MVC (.NET 6) project with a WCF service reference.

Exception

System.NotSupportedException: 'Method GetData is not supported on this proxy, this can happen if the method is not marked with OperationContractAttribute or if the interface type is not marked with ServiceContractAttribute.'

Stack Trace

System.NotSupportedException: Method GetData is not supported on this proxy, this can happen if the method is not marked with OperationContractAttribute or if the interface type is not marked with ServiceContractAttribute.
at System.ServiceModel.Channels.ServiceChannelProxy.GetMethodData(MethodCall methodCall)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)
at generatedProxy_1.GetData(Int32 )
at ServiceReference1.Service1Client.GetData(Int32 value)
at MvcCore6.Controllers.HomeController.Index()
at lambda_method18(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Sample project
MvcCore6WcfTest.zip

Screenshots
image

Additional context
The ASP.NET MVC project and the WCF service project were created using the default templates.

@mchlstrng mchlstrng changed the title System.NotSupportedException when using Hot Reload (VS 2022) System.NotSupportedException when using Hot Reload (VS 2022 - .NET 6) Feb 17, 2022
@daydraze
Copy link

I am also receiving this exception, but it seems rather random as towards when it occurs. Tried to recreate it by hot reloading, but it is rather hit or miss whether it works.

@daydraze
Copy link

I am also receiving this exception, but it seems rather random as towards when it occurs. Tried to recreate it by hot reloading, but it is rather hit or miss whether it works.

Okay, I narrowed it, it occurs on a hot reload when you change something in the controller on the page that is opened. (when you change something in another controller and hotreload, it does not occurs). Once you hot reload it, the system will keep giving the system not supported exception until you restart the application.

@mconnew
Copy link
Member

mconnew commented Mar 10, 2022

After talking to a few colleagues, I believe I know how to fix this. In MethodInfoOperationSelector we use the MethodInfo object obtained by reflection during ChannelFactory creation to lookup which operation is for that MethodInfo. When hot reload happens, the CLR invalidates some MethodInfo types from it's cache which means a fresh lookup of the MethodInfo will yield a different instance. We should be able to make a simple change to use MethodInfo.MethodHandle.Value as the key instead. I've been told by those who know more about this than me that the method handle value should be stable. We don't actually need the MethodInfo object for anything in this code path so this should be sufficient. We do use MethodInfo.Invoke to execute callback contracts, but looking at the implementation, the Invoke call happens via the MethodHandle.Value so should continue to work.

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

Successfully merging a pull request may close this issue.

3 participants