将现有项目转换为 Silverlight 4 时出现问题

2024-01-18

我们有一个正在运行的 Silverlight 3 项目。将目标框架更改为 Silverlight 4 后,应用程序将不再启动。它在生成的 InitializeComponent() 方法中的以下行中引发异常:

System.Windows.Application.LoadComponent(this, new System.Uri("/SLAppMain;component/App.xaml", System.UriKind.Relative));

这是异常(注意内部异常):

System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
  LineNumber=0
  LinePosition=0
  StackTrace:
       bei System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
  InnerException: System.TypeLoadException
       Message=Der Typ 'System.Security.AllowPartiallyTrustedCallersAttribute' konnte nicht aus der mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e -Assembly geladen werden.
       StackTrace:
            bei System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            bei System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            bei System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            bei System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
            bei System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
            bei System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
            bei MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
            bei MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
       InnerException: 

问题在于 System.Security.AllowPartiallyTrustedCallersAttribute 类型不包含在 Silverlight 版本的 mscorlib.dll 中。

我不知道如何解决这个问题,也不知道在哪里寻找原因。有人遇到过这个问题吗?什么可能导致此错误?


SL 4 中不存在AllowPartiallyTrustedCallersAttribute 类(mscorlib 中也不存在,其他任何地方也不存在),SL 3 中也不存在。 因此,我想肯定不仅仅是从 SL 3 到 SL 4 的转换 - 您的代码中是否在某处使用了AllowPartiallyTrustedCallersAttribute?

干杯,亚历克斯

编辑:实际上,您可能想查看应用程序的 AssemblyInfo.cs (在 Properties 文件夹中)。也许该属性在那里使用,例如

[assembly: AllowPartiallyTrustedCallers(true)]

。然后你可以简单地删除它,看看会发生什么......

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将现有项目转换为 Silverlight 4 时出现问题 的相关文章

随机推荐