Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
getup700 opened this issue Jun 26, 2024 · 2 comments
Closed

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

getup700 opened this issue Jun 26, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@getup700
Copy link
Contributor

getup700 commented Jun 26, 2024

我用微软提供的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
Copy link
Owner

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

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

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

@shichuyibushishiwu shichuyibushishiwu pinned this issue Jun 26, 2024
@shichuyibushishiwu shichuyibushishiwu added the documentation Improvements or additions to documentation label Jun 26, 2024
@getup700
Copy link
Contributor Author

找到问题了,是因为我在ioc容器build前调用了容器注入,和外部事件服务的声明周期没有关系。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants