2010-05-26 41 views
2

我们有一个Silverlight 3项目。将目标框架更改为Silverlight 4后,应用程序将不再启动。它抛出异常在生成的InitializeComponent以下行()方法:将现有项目转换为Silverlight 4的问题

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中。

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

回答

1

AllowPartiallyTrustedCallersAttribute类在SL 4中不存在(既不在mscorlib中,也不在其他任何地方),SL 3中也不存在。 所以必须有不仅仅是SL 3到SL 4的转换,我猜 - 你的代码中是否使用了AllowPartiallyTrustedCallersAttribute?

干杯,亚历克斯

编辑:其实,你可能想看看到你的应用程序的AssemblyInfo.cs中(在属性文件夹)。或许属性用于有像

[assembly: AllowPartiallyTrustedCallers(true)] 

。然后,您可以简单地将其删除,看看会发生什么...

+0

我搜索了整个解决方案,但没有找到该属性。 – user351008 2010-05-26 15:15:51

+0

您是否搜索“AllowPartiallyTrustedCallersAttribute”或“AllowPartiallyTrustedCallers”?您应该搜索“AllowPartiallyTrustedCallers”,因为“-Attribute”部分在使用时可以省略。 – 2010-05-26 15:23:07

+0

我的确如此。 – user351008 2010-05-26 15:59:11

0

您是否在项目中使用Unity for silverlight?我昨天有完全相同的问题,当我去参考的统一

0

做一个干净的构建,然后完全重建修复了这个问题的错误消失我。

0

依赖与同名会悄悄地覆盖并封装成编译后XAP,所以请确保您的项目不同的目标平台不建到相同的输出文件夹

相关问题