shichuyibushishiwu / Tuna.Revit.Extensions

Revit Api Extension
https://shichuyibushishiwu.github.io/
MIT License
32 stars 15 forks source link

注册IExternalEventService到IOC容器时发生故障 #53

Open getup700 opened 5 days ago

getup700 commented 5 days ago

我用微软提供的mvvm包注册scoped周期的ExternalEventService服务时,在build容器时发生报错。错误信息如下:

System.IO.FileLoadException:“未能加载文件或程序集“Tuna.Revit.Extension, Version=2023.0.15.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。无效指针 (异常来自 HRESULT:0x80004003 (E_POINTER))”

服务注册代码如下:

services.AddScoped<IExternalEventService, ExternalEventService>();

注:Microsfot.CommunityToolkit.Mvvm版本8.2.0;Tuna.Revit.Extension版本2023.0.15.0;

shichuyibushishiwu commented 5 days ago

基于 Revit 外部事件的机制,扩展包里把 IExternalEventService 封装成了单例,可以尝试修改它的注册放置,示例如下

//在有效上下文进行实例化
IExternalEventService service = new ExternalEventService();

//注册单例服务,并传入实例
services.AddSingleton<IExternalEventService>(service);