Orleans 序列化遇到的坑

真的是巨坑

搞明白问题的我简直无法用言语来描述我的心情

先上架构图

理想中的架构

服务随便上 网关只负责分发

然后跟随官方教程写遇到了序列化问题

以前有经验,不慌,以前稀里糊涂就搞定了。

再然后遇到一个令人崩溃的问题

One or more errors occurred. (Named type "Entity.BookCategory" is invalid: Type string "Entity.BookCategory" cannot be resolved.) ---> System.TypeAccessException: Named type "Entity.BookCategory"

Entity.BookCategory这个自行替换成实体类文件名

中间出现的描述词是在太少

为一一个描述is invalid: Type string 却没什么卵用  摸不着头脑

在然后注意到报错的类是System.

TypeAccessException

The exception that is thrown when a method attempts to use a type that it does not have access to.

翻译过来是没有访问权限抛出的异常

一脸懵逼

Entity是基础库 大家都引用了

只有Gateway没有引用

于是引用Entity库

这个是Github上大佬给出的解决方法

最开始我是用的第一个解决方法

在Gateway安装两个Nuget,没有解决

.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(BookCategory).Assembly).WithReferences())

然后转为第三种方法,诶 跑动了

还没高兴一会。

做了个测试,

网关启动

修改服务逻辑 添加新的类

启动服务与客户端

问题又出来了

这可真是叫人绝望啊

意味着每一次新增实体都要重启网关。

这是在逗我?

也大概能猜到为什么

Orleans是预编译

他在程序启动的时候执行扫包,编码,生成类文件

新增的实体没有被生成类文件。

当然没有权限访问,因为根本不存在。

原文地址:https://www.cnblogs.com/AnAng/p/11040216.html