gpt4 book ai didi

c# - 为什么这段代码在将近一年的时间里运行良好却无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:16 25 4
gpt4 key购买 nike

自动软件更新是否会导致某些模块属性不起作用?我真的对我在这里发布的这个功能感到困惑。它们基本上与从当前正在执行的程序集中读取图像 Logo 的功能相同。名为“Get2LogoImageStream”的函数与“Get1LogoImageStream”的区别仅在于 Current.ManifestModule.Name 与 Current.ManifestModule.ScopeName。

此“Current.ManifestModule.Name”版本的代码适用于 Web From 应用程序和 Windows 窗体应用程序,但目前它仅适用于 Windows 应用程序窗体。但是,当我将此代码“Current.ManifestModule.Name”更改为“Current.ManifestModule.ScopeName”时,它可以在 WEB 上正常工作。所以我想问 C# 或 VB.NET 开发人员的问题是,自动软件更新会导致此类问题吗?

  protected Stream Get1LogoImageStream()
{
Assembly current = Assembly.GetExecutingAssembly();
string imageName = "logo.jpg";
string file = string.Format("{0}.{1}", current.ManifestModule.ScopeName.Replace(".dll", string.Empty), imageName);
return current.GetManifestResourceStream(file);
}


protected Stream Get2LogoImageStream()
{
Assembly current = Assembly.GetExecutingAssembly();
string imageName = "logo.jpg";
string file = string.Format("{0}.{1}", current.ManifestModule.Name.Replace(".dll", string.Empty), imageName);
return current.GetManifestResourceStream(file);
}

最佳答案

由于 .Name 仅返回程序集而 .ScopeName 返回完整路径,似乎是某些原因导致您的程序需要 Logo 文件的绝对路径才能运行。

从那里开始,可能会有很多事情,想法从我的脑海中浮现出来:1) 你有一个环境变量存储允许找到它的图像的路径。

2) 您移动了图像或程序集,或者以某种方式更改了程序集运行的上下文,这样它就在错误的位置搜索图像。

3) 某些 .NET 更新要求使用完全限定名称的可能性很小,但我对此表示怀疑。

没有更多细节,很难说。

关于c# - 为什么这段代码在将近一年的时间里运行良好却无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/774420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com