dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.06k stars 2.03k forks source link

Orleans 4 GenerateSerializer Attribute #8029

Closed NSTA2 closed 1 year ago

NSTA2 commented 1 year ago

I'm trying to migrate an Orleans project to 4.0. I have a type (SimManager.Models.Sample) which is returned as a result from a grain method. It's in a different project from my silo. I've marked it with the [GenerateSerializer] attribute and added an [Id(x)] attribute to each class member. The project which contains the type references the Microsoft.Orleans.CodeGenerator.MSBuild nuget package. However, on silo start up, I still get the error below.

Are there any other steps required to cause the serializer to be generated?

info: Orleans.Runtime.Silo[100422]
      -------------- Started silo S172.17.224.1:11111:403876020, ConsistentHashCode D5489472 --------------
Host Error: Orleans.Runtime.OrleansConfigurationException: Found unserializable or uncopyable types which are being referenced in grain interface signatures:
Type: SimManager.Models.Sample has no serializer or copier and was referenced by the following:
        * SimManager.Interfaces.ILogicalTwinGrain2,SimManager methods: System.Threading.Tasks.Task1[SimManager.Models.Sample] GetNextSample()
Ensure that all types which are used in grain interfaces have serializers available for them.
Applying the [GenerateSerializer] attribute to your type and adding [Id(x)] attributes to serializable properties and fields is the simplest way to accomplish this.
Alternatively, for types which are outside of your control, serializers may have to be manually crafted, potentially using surrogate types.

   at Orleans.SerializerConfigurationValidator.Orleans.IConfigurationValidator.ValidateConfiguration() in /_/src/Orleans.Core/Configuration/Validators/SerializerConfigurationValidator.cs:line 94
   at Orleans.Hosting.SiloHostedService.ValidateSystemConfiguration(IEnumerable1 configurationValidators) in /_/src/Orleans.Runtime/Hosting/SiloHostedService.cs:line 41
   at Orleans.Hosting.SiloHostedService..ctor(Silo silo, IEnumerable1 configurationValidators, ILogger1 logger) in /_/src/Orleans.Runtime/Hosting/SiloHostedService.cs:line 20
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable(IEnumerableCallSite enumerableCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType)
   at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)

The offending class:

namespace SimManager.Models
{
    using Orleans;
    using System;
    using System.Collections.Generic;

    [GenerateSerializer]
    public class Sample
    {
        [Id(0)]
        public Guid Id { get; set; }

        [Id(1)]
        public Dictionary<string, double[]> Values { get; set; }
    }
}

Using latest version of Visual Studio (and .NET 7):

Microsoft Visual Studio Enterprise 2022
Version 17.3.6
VisualStudio.17.Release/17.3.6+32929.385
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Enterprise

Visual C++ 2022   00476-80000-00000-AA207
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.3.376.3011
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.3.376.3011
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.3.376.3011
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Quantum Development Kit   0 and 1
Microsoft Quantum Development Kit provides support for developing quantum algorithms in the Q# programming language.

Mono Debugging for Visual Studio   17.3.20 (3f4cb00)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62207.04100
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.10701.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Visual Studio Tools for Unity   17.3.0.0
Visual Studio Tools for Unity

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSPackage Extension   1.0
VSPackage Visual Studio Extension Detailed Info

Xamarin   17.3.0.308 (d17-3@56b9f7e)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.3.0.217 (remotes/origin/d17-3@b81db1dcc0)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.2.28 (9b3d244)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   13.0.0.0 (d17-3/030cd63)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: dffa5ab
    Java.Interop: xamarin/java.interop/d17-3@7716ae53
    SQLite: xamarin/sqlite/3.38.5@df4deab
    Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6

Xamarin.iOS and Xamarin.Mac SDK   16.0.0.75 (e4f48bed7)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
benjaminpetit commented 1 year ago

Did you install Microsoft.Orleans.Sdk package in your project?

NSTA2 commented 1 year ago

That was it, thank you very much! Is there a doc outlining package requirements? (I haven't seen this one before, is it new to Orleans 4?)

benjaminpetit commented 1 year ago

We don't have doc up yet for the next version (we are going from version 3.6 to 7 directly, to align with dotnet). And yes, that's a new package.

NSTA2 commented 1 year ago

Thanks for your help and for such an excellent system <3