【发布时间】: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)
【问题讨论】: