【问题标题】:WinForm crashing when accessing resourcesWinForm在访问资源时崩溃
【发布时间】:2014-02-22 09:57:58
【问题描述】:

我正在开发一个 WinForm 应用程序,并且我有一些嵌入式资源(表单的图形布局)。问题是当我在我的机器上启动应用程序时它运行完美,但如果我将它传递到另一台电脑上它可能会或可能不会工作。在我尝试的最后一台计算机(Windows 7 64 位,安装了 .NET 4.0)上,当我尝试访问资源时它被阻止了。这是阻止应用程序的代码,下面是抛出的完整异常。

//Note: notifierName is a string passed as an argument
_icon = new NotifyIcon
{
    Text = notifierName,
    Icon = SystemIcons.Application,//Properties.Resources.Tray,
    Visible = true
};
try
{
    _icon.Icon = Properties.Resources.Tray;
}
catch (Exception e)
{
    Logger.WriteLog(e.ToString());
}

在追踪导致异常的原因后,我尝试将所有资源设置为“嵌入式资源”,.exe 的大小增加了一倍(因此图像实际上保存在那里)但发生了同样的错误。我想我错过了一些关于资源如何工作的东西,因为在另一台机器上传递相同的 exe 并不会导致所有这些麻烦。感谢您的帮助。

System.TypeLoadException:无法加载类型“System.Runtime.CompilerServices.ExtensionAttribute”dall'程序集“mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”。 在 System.ModuleHandle.ResolveMethod(RuntimeModule 模块,Int32 methodToken,IntPtr* typeInstArgs,Int32 typeInstCount,IntPtr* methodInstArgs,Int32 methodInstCount) 在 System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule 模块,Int32 methodToken,IntPtr[] typeInstantiationContext,Int32 typeInstCount,IntPtr[] methodInstantiationContext,Int32 methodInstCount) 在 System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule 模块,Int32 methodToken,RuntimeTypeHandle[] typeInstantiationContext,RuntimeTypeHandle[] methodInstantiationContext) 在 System.Reflection.CustomAttributeData..ctor(RuntimeModule 范围,CustomAttributeRecord caRecord) 在 System.Reflection.CustomAttributeData.GetCustomAttributes(RuntimeModule 模块,Int32 tkTarget) 在 System.Reflection.CustomAttributeData.GetCustomAttributesInternal(RuntimeAssembly 目标) 在 System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(程序集 a,UltimateResourceFallbackLocation&fallbackLocation) 在 System.Resources.ResourceManager.CommonSatelliteAssemblyInit() 在 System.Resources.ResourceManager..ctor(字符串 baseName,程序集程序集) 在 PatcherNET4.Properties.Resources.get_ResourceManager() 在 PatcherNET4.CustomControls.Notifier.Create(String notifierName)

【问题讨论】:

    标签: c# .net winforms


    【解决方案1】:

    当您使用.Net 4.5 编译应用程序但在4.0.In .Net 4.5 上运行ExtensionAttributeSystem.Core 中删除并添加mscorlib 时会发生此错误。

    Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib

    Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0 Error

    【讨论】:

    • 很好的建议,你肯定是对的。现在,如何将目标平台从 VS 中的解决方案属性更改为 .NET 4.0?
    • 我想改变目标,但你可以同时测试。
    • 它已经设置为 .NET 4.0,但现在我认为问题可能出在引用的 DLL 中。我去看看
    • 它还在崩溃。我引用的唯一 dll 是 protobuf-net(来自 Marc Gravell),我 100% 确定我正在通过 .NET 4.0 版本。
    • 这里发布了这个问题的一个很好的细分:stackoverflow.com/questions/13748055/…
    猜你喜欢
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多