visual studio 2022 - FileExtensionRegistryService returns me UNKNOWN content type for .cs and .txt - Stack Overflow

In the Visual Studio Extension development scenario, I try to get content types as follows.var compone

In the Visual Studio Extension development scenario, I try to get content types as follows.

var componentModel = (IComponentModel)Package.GetGlobalService(serviceType: typeof(SComponentModel));

var fileExtensionRegistryService = componentModel.GetService<IFileExtensionRegistryService>();

var extensionString = "cs";

var contentTypeForGivenExtension = fileExtensionRegistryService.GetContentTypeForExtension(extension: extensionString);

extensionString = "txt";

contentTypeForGivenExtension = fileExtensionRegistryService.GetContentTypeForExtension(extension: extensionString);

The contentTypeForGivenExtension.DisplayName for both the cs as well txt cases above, is UNKNOWN. Why is that? Am I missing something here?

Also I dont get any extensions for CSharp and text content types in the following.

var contentTypeRegistryServiceLocal = componentModel.GetService<IContentTypeRegistryService>();

// I get a total of 95 content types here.
var contentTypeList = contentTypeRegistryServiceLocal.ContentTypes.
    OrderBy(keySelector: contentType => contentType.TypeName).ToList();

// I get the text Content Type correctly here. 
var textContentType = contentTypeList.
    Where(predicate: contentType => contentType.DisplayName.Equals("text")).First();

// I get the extensionList count as 0 here for text content type. Not sure why
var extensionListForTextContentType = fileExtensionRegistryService.
    GetExtensionsForContentType(contentType: textContentType).ToList();

// I get the CSharp Content Type correctly here. 
var cSharpContentType = contentTypeList.
    Where(predicate: contentType => contentType.DisplayName.Equals("CSharp")).First();

// I get the extensionList count as 0 here for CSharp content type. Not sure why
var extensionListForCSharpContentType = fileExtensionRegistryService.
    GetExtensionsForContentType(contentType: cSharpContentType).ToList();

So what am I missing here?

If you want to take a look at the full Visual Studio solution, its here. And the command file is this.

There is more.

Instead of cs and txt, if I register a custom content type, then it works.

Take a look at this example here.

I define a FooAbcd ContentType here.

public class FooAbcdContentDefinition
{
    public const string ContentTypeName = "FooAbcd";
    // Comment out the following eight lines, to test content types registration.
    [Export]
    [Name(ContentTypeName)]
    [BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
    internal static ContentTypeDefinition FooContentTypeDefinition;
    [Export]
    [FileExtension(".FooAbcd")]
    [ContentType(ContentTypeName)]
    internal static FileExtensionToContentTypeDefinition FooFileExtensionDefinition;
}

And from the IFileExtensionRegistryService I get the FooAbcd ContentType as follows.

var contentTypeRegistryService = componentModel.GetService<IContentTypeRegistryService>();

var contentTypeList = contentTypeRegistryService.ContentTypes.
    OrderBy(contentType => contentType.TypeName).ToList();
    
var fooAbcdContentType = contentTypeList.Where(contentType => contentType.DisplayName == FooAbcdContentDefinition.ContentTypeName).FirstOrDefault();

// Then I get the fileExtensionRegistryService
var fileExtensionRegistryService = componentModel.GetService<IFileExtensionRegistryService>();

var extensionListForFooAbcdContentType = fileExtensionRegistryService.GetExtensionsForContentType(fooAbcdContentType).ToList();

Now I get the file extension from the content type as follows.

// Then I get the fileExtensionRegistryService
var fileExtensionRegistryService = componentModel.GetService<IFileExtensionRegistryService>();

var extensionListForFooAbcdContentType = fileExtensionRegistryService.GetExtensionsForContentType(fooAbcdContentType).ToList();

And extensionListForFooAbcdContentType contains the extension. Run the example available at my github

So the the problem is only with cs and txt. But things work correctly with custom content type.

What am I missing?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745664363a4639034.html

相关推荐

  • 重装系统只影响C盘吗?深入解析系统重装的全过程

    重装系统只影响C盘吗?深入解析系统重装的全过程 在计算机的日常使用中,重装系统是一个常见的操作,尤其是在系统出现故障、感染病毒或需要优化系统性能时。然而,许多用户对于重装系统的具体过程和影响存在误解,认为重装系统仅仅是对C盘进行清空和重置

    45分钟前
    10
  • 大模型驱动金融数据应用的实战探索

    近年来,人工智能技术的飞速发展正在重塑全球各行各业的生态格局,金融行业作为数据密集型领域,更是首当其冲。大模型凭借其强大的自然语言处理、逻辑推理和生成能力,逐渐成为金融数据应用的核心驱动力。本文将从行业背景与趋势、核心场景重构、产品能力提升

    44分钟前
    00
  • 拥抱国产化:转转APP的鸿蒙NEXT端开发尝鲜之旅

    本文由转转技术团队赵卫兵分享,原题“鸿蒙新篇章:转转 APP 的 HarmonyOS Next 开发之旅”,下文进行了排版优化和内容修订。1、引言2023 年在华为开发者大会(HDC.Together)上,除了面向消费者的 HarmonyO

    42分钟前
    00
  • 在VMware虚拟机中安装Windows 7全攻略(避坑指南)

    ⚠️写在前面 最近发现很多开发者在调试老旧系统时都需要用到Windows 7环境&#xff08;特别是银行、医疗等行业的遗留系统&#xff09;&#xff0c;但实体机安装既不现实也不安全。今天就手把手教你在虚拟机

    37分钟前
    00
  • 最后讲一遍:ChatGPT 快速生成国内外研究现状的方法

    在科研工作中,梳理国内外研究现状有助于明确研究方向,发现研究空白,为后续研究提供理论支持与创新思路。本文将详细介绍如何借助 ChatGPT 高效生成国内外研究现状,帮助您在有限时间内构建全面、专业的文献综述框架,提升学术写作效率与质量。St

    34分钟前
    00
  • 雨晨 22635.5170 Windows 11 企业版 23H2 轻装版

    文件: 雨晨 22635.5170 Windows 11 企业版 23H2 轻装版 install.esd 大小: 2920270404 字节 修改时间: 2025年4月8日, 星期二, 11 : 04 : 59 MD5: D5F8F0AD

    34分钟前
    00
  • 人工智能适合什么人学

    一、引言:人工智能浪潮下的新机遇在当今科技飞速发展的时代,人工智能(AI)无疑是最为耀眼的技术明星之一。从智能语音助手到自动驾驶汽车,从医疗诊断辅助到金融风险预测,人工智能正以前所未有的速度改变着我们的生活和工作方式。随着全球领先的终身学习

    33分钟前
    00
  • Windows系统密钥检测工具PIDKey 2.1中文版

    Windows系统密钥检测工具PIDKey 2.1中文版 【下载地址】Windows系统密钥检测工具PIDKey2.1中文版 Windows系统密钥检测工具PIDKey 2.1中文版是一款功能强大的工具&#xff0c;专为管理Win

    32分钟前
    00
  • 子网掩码是怎么“掩”的?用积木教你彻底搞懂!

    子网掩码是怎么“掩”的?用积木教你彻底搞懂!前言肝文不易,点个免费的赞和关注,有错误的地方请指出,看个人主页有惊喜。作者:神的孩子都在歌唱你是不是也曾被“子网掩码”这个术语搞得晕头转向?明明是学网络的第一步,却像是打开了数学世界的大门:2

    31分钟前
    00
  • 1.54G 雨晨 26100.3775 Windows 11 IoT 企业版 LTSC 24H2 极速版

    精简AERO外主题并增加一套壁纸主题&#xff08;默认启用&#xff09;误杀导致功能界面空白、因WMIC被默认移除系统可能会多次重启。 拒止连接 www.5909 拒止连接 www.mnpc 拒止连接 quark 拒止

    31分钟前
    00
  • ​2025 轻松部署 Odoo 18 社区版

    随着 Odoo 18 社区版的发布,越来越多的企业希望借助这款开源 ERP 系统实现数字化转型。本文将深入解析传统部署方式的底层逻辑,并揭示如何通过自动化工具实现零门槛快速部署。一、手工部署 Odoo 18 技术全解 Docker 环境搭建

    28分钟前
    00
  • Java&amp;Activiti7实战:轻松构建你的第一个工作流

    本文已收录在Github,关注我,紧跟本系列专栏文章,咱们下篇再续!

    26分钟前
    00
  • 设计模式:工厂方法模式(Factory Method)(2)

    当年做一个项目时,还不懂什么是设计模式,仅仅是按照经验完成了需求。回头看看,就是暗合桥接模式。但是,在整个需求实现过程中,甲方需要我在已经设计好的标准业务逻辑中添加非标的需求,因为,在他们眼里,从业务角度来看,是自然的拓展。如果当年我知道还

    20分钟前
    00
  • win11家庭版改为专业版

    找到“我的电脑”--“设置”--“系统”--“激活”--“更改密钥” 输入密钥“G49HN-9YQCT-684C3-R7T3F-3DBQB 即可成功。

    18分钟前
    00
  • OpenAI“Agent 圣经”翻车?LangChain 创始人怒怼“全是坑”!

    整理 | Tina当前,AI 领域呈现出一种近乎“追星式”的热情氛围,每当有新的东西发布,便迅速引发广泛关注与高度评价,仿佛技术变革即将一触即发。同时大家情绪也波动剧烈,从“危机论”到“爆发论”频繁切换。OpenAI 最近出的《A Pra

    15分钟前
    00
  • 「全球首个自回归视频生成大模型」,刚刚,Swin Transformer作者创业团队重磅开源!

    机器之心编辑部视频生成领域,又出现一位重量级开源选手。今天,马尔奖、清华特奖得主曹越的创业公司 Sand AI 推出了自己的视频生成大模型 ——MAGI-1。这是一个通过自回归预测视频块序列来生成视频的世界模型,生成效果自然流畅,还有多个版

    13分钟前
    00
  • IDEA 2025.1 版震撼发布,建议更新

    好久不见甚是想念,有小伙伴催更了。 各位编程大神们!今天我要给大家带来一个超级劲爆的消息!IntelliJ IDEA 2025.1 终极版震撼发布啦!就像一颗超级炸弹在编程界炸开,这些新特性能让咱们的开发效率直接翻倍,简直爽歪歪

    10分钟前
    10
  • Claude竟藏着3307种「人格」?深扒70万次对话,这个AI会看人下菜碟

    新智元报道编辑:定慧 英智【新智元导读】AI会无脑附和吗?Anthropic研究发现,Claude能根据场景切换人格:谈恋爱时化身情感导师,聊历史时秒变严谨学者。一些对话中,它强烈支持用户价值观,但在3%的情况下,它会果断抵制。想象一

    7分钟前
    10
  • 142页长文揭秘DeepSeek

    新智元报道编辑:定慧【新智元导读】DeepSeek-R1是近年来推理模型领域的一颗新星,它不仅突破了传统LLM的局限,还开启了全新的研究方向「思维链学」(Thoughtology)。这份长达142页的报告深入剖析了DeepSeek-R

    6分钟前
    10
  • 通过Windows镜像离线升级或修复Win10系统

    通过Windows镜像离线升级或修复Win10系统 导航 文章目录 通过Windows镜像离线升级或修复Win10系统导航关键条件与原理查询系统版本下载镜像打开镜像进行更新修复 关键条件与原理 版本一致性 需确保镜像的**SKU&am

    3分钟前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信