2010-05-26 45 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,所以請確保您的項目不同的目標平臺不建到相同的輸出文件夾

相關問題