2016-10-12 4 views
2

서비스 패브릭에서 배우를 원격 처리하려고 할 때 다음 예외가 발생합니다 : "지정된 캐스트가 유효하지 않습니다.".서비스 패브릭 Actor 원격 호출에서 "지정된 캐스트가 유효하지 않습니다."가 표시됩니다. 예외

초기화를 actorProxy

의 방법의
private static Uri serviceUri = new Uri("fabric:/ServiceFabricVoting/MyTestActorService"); 
private static IMyTestActor myActorProxy = ActorProxy.Create<IMyTestActor>(ActorId.CreateRandom(), serviceUri); 

콜링 :

var number = await myActorProxy.GetCountAsync(); 

배우 구현 다음과 같이

내 코드는

[StatePersistence(StatePersistence.Persisted)] 
    internal class MyTestActor : Actor, IMyTestActor 
    { 
     /// <summary> 
     /// Initializes a new instance of MyTestActor 
     /// </summary> 
     /// <param name="actorService">The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this actor instance.</param> 
     /// <param name="actorId">The Microsoft.ServiceFabric.Actors.ActorId for this actor instance.</param> 
     public MyTestActor(ActorService actorService, ActorId actorId) 
      : base(actorService, actorId) 
     { 
     } 

     /// <summary> 
     /// This method is called whenever an actor is activated. 
     /// An actor is activated the first time any of its methods are invoked. 
     /// </summary> 
     protected override Task OnActivateAsync() 
     { 
      ActorEventSource.Current.ActorMessage(this, "Actor activated."); 

      // The StateManager is this actor's private state store. 
      // Data stored in the StateManager will be replicated for high-availability for actors that use volatile or persisted state storage. 
      // Any serializable object can be saved in the StateManager. 
      // For more information, see https://aka.ms/servicefabricactorsstateserialization 

      return this.StateManager.TryAddStateAsync("count", 0); 
     } 

     /// <summary> 
     /// TODO: Replace with your own actor method. 
     /// </summary> 
     /// <returns></returns> 
     Task<int> IMyTestActor.GetCountAsync() 
     { 
      return this.StateManager.GetStateAsync<int>("count"); 
     } 

     /// <summary> 
     /// TODO: Replace with your own actor method. 
     /// </summary> 
     /// <param name="count"></param> 
     /// <returns></returns> 
     Task IMyTestActor.SetCountAsync(int count) 
     { 
      // Requests are not guaranteed to be processed in order nor at most once. 
      // The update function here verifies that the incoming count is greater than the current count to preserve order. 
      return this.StateManager.AddOrUpdateStateAsync("count", count, (key, value) => count > value ? count : value); 
     } 
    } 

을 그리고 이것은 스택 그럴이다 에이스 예외 :

" at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Common.NativeServiceCommunication.CreateServiceCommunicationClient(Guid& iid, IntPtr transportSettingsPtr, IntPtr connectionAddress, IFabricCommunicationMessageHandler notificationHandler, IFabricServiceConnectionEventHandler connectionEventHandler)\r\n at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.CreateNativeClient(FabricTransportSettings transportSettings, String connectionAddress, NativeClientConnectionEventHandler eventHandler, IServiceRemotingCallbackClient contract)\r\n at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.NativeServiceCommunicationClient.<>c__DisplayClass2.<.ctor>b__0()\r\n at System.Fabric.Interop.Utility.<>c__DisplayClass13.<WrapNativeSyncInvoke>b__12()\r\n at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func`1 func, String functionTag, String functionArgs)\r\n at System.Fabric.Interop.Utility.RunInMTA(Action action)\r\n at Microsoft.ServiceFabric.Services.Communication.FabricTransport.Client.FabricTransportServiceRemotingClientFactoryImpl.CreateClientAsync(String endpoint, CancellationToken cancellationToken)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<CreateClientWithRetriesAsync>d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<GetClientAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientFactoryBase`1.<GetClientAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Client.FabricTransportServiceRemotingClientFactory.<Microsoft.ServiceFabric.Services.Communication.Client.ICommunicationClientFactory<Microsoft.ServiceFabric.Services.Remoting.Client.IServiceRemotingClient>.GetClientAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.<GetCommunicationClient>d__22.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Communication.Client.ServicePartitionClient`1.<InvokeWithRetryAsync>d__7`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Remoting.Client.ServiceRemotingPartitionClient.<InvokeAsync>d__8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<InvokeAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyBase.<ContinueWithResult>d__7`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at VotingService.VotingService.<ProcessRequestAsync>d__4.MoveNext() in C:\\Users\\mlani\\Develop\\ServiceFabricVoting\\VotingService\\VotingService.cs:line 148" 

로컬 클러스터에서 응용 프로그램을 테스트하고 있습니다. 액터 클래스와 액터 인터페이스의 구현은 프로젝트에 액터 서비스를 추가 한 후에 생성 된 기본 액터입니다.

조언 해 주셔서 감사합니다.

+0

코드 스 니펫을 사용하여 문제를 재현하려고했지만 오류가 발생하지 않았습니다. "myActorProxy"라는 프록시를 만든 다음 "myActorServiceProxy"를 호출한다는 사실을 알았습니까? 아마도 잘못된 것을 호출하고 있습니까? 액터 구현을 추가 할 수 있습니까? –

+0

죄송합니다. 이것은 코드 스 니펫을 게시 할 때 실수였습니다. 나는 원래 게시물에 액터 구현을 추가했습니다. 고맙습니다. –

+0

감사합니다. 호기심 때문에 로컬 컴퓨터에 어떤 버전의 Service Fabric SDK 및 런타임을 설치 했습니까? 그리고 프로젝트에서 사용중인 NuGet 패키지의 버전은 무엇입니까? SDK 및 런타임의 경우 프로그램 및 기능에서 "Microsoft Azure Service Fabric"을 찾으십시오. –

답변

3

나는 똑같은 문제에 직면 해있다. 나는 무국적 서비스에서 배우 서비스를 부르고 있었다. 문제는 상태 비 저장 서비스가 Microsoft.ServiceFabric.Actors nuget 패키지의 다른 버전을 사용한다는 것입니다. 버전을 동일하게 변경 한 후에는 문제가 사라졌습니다.

이 문제는 stateless/stateful 서비스에서 참조하는 것과 다른 버전의 서비스 패브릭 SDK를 사용하는 경우 발생할 수 있습니다.