This has been bugging me all day and I have yet to figure out why this is happening.
Basic scenario
Created a new Service Fabric Application with an ASP.NET Core service and added support for returning MVC views so that it can act as the UI for my SF App.
Added an Actor service for users to the solution which created the
UserActor
andUserActor.Interfaces
projects and ensured that the Interfaces library targets x64 as required by SF.Defined a
Task<UserProfile> GetProfileData()
method on the UserActor where theUserProfile
type is a concrete class defined in the Interfaces project with the[DataContract]
and[DataMember]
attributes so that it can be serialized (all members are primitives).Added a project reference to the
UserActor.Interfaces
from the ASP.NET Core project so I could create the actor proxy and invoke the method.Added the code in the ASP.NET Core Controller class to connect to the actor instance and invoke the
GetProfileData
method
At this point, I receive the following compiler error:
error CS0246: The type or namespace name 'UserProfile' could not be found (are you missing a using directive or an assembly reference?)
The relevant lines of code are as follows:
using UserActor.Interfaces;
var user = ActorProxy.Create<IUserActor>( new ActorId( model.email ), FabricAppUrl );
UserProfile profile = user.GetProfileData().Result; // compiler error here
If I hover over the UserProfile type on the last line, Visual Studio shows me it sees the type as UserActor.Interfaces.UserProfile
and doesn't show any errors in the editor. It's only when I compile that this error shows up.
I didn't receive this error when trying to return a primitive type and it had no problem resolving the IUserActor
interface for the Actor Proxy either.
Does this have something to do with the fact the the Actor projects are standard .NET projects and the ASP.NET Core project is compiled using dotnet build (set to .NETFramework,Version=v4.5.2; not dotnet core).
I also noticed in the build output that the ASP.NET Core project is building as 'Debug Any CPU' while all of the other projects are set to 'Debug x64'. If this were the issue I would expect to receive an error about mis-matched architecture types, but I'm not getting that either.
How can I resolve this? Should I be returning the data from the Actor in a different manner (such as json serializing it before returning it as a string primitive)?
Edit 1:
The code sample above was too simplistic. The 2 compiler errors I am seeing are around the type being passed to a helper method in the same controller as follows:
private bool TryGetUserProfile( LoginModel model, out UserProfile profile )
{
var user = ActorProxy.Create<IUserActor>(new ActorId(model.Email), FarbicAppUrl);
var profile = user.GetProfileData().Result;
return !string.IsNullOrEmpty(profile.Name);
}
UserProfile
byvar
? – Kalten[DataContract]
and several get/set auto properties attributed with[DataMember]
. – KyKo