2011-07-18 16 views
7

Comment puis-je faire fonctionner mon déploiement d'applications?WPF ClickOnce et problème de confiance partielle

J'ai créé un nouveau projet WPF simple avec Visual Studio 2010 et effectué les modifications suivantes dans les propriétés du projet: -> Signature: création du certificat de test et signature des deux assemblages et des manifestes. N'a pas coché la case "Signe différé seulement" -> Sécurité: Case cochée "Activer le clic sur les paramètres de sécurité" et bouton radio "Ceci est un paramétrage partiel de confiance". Zone: "Intranet local". -> Sécurité, Avancé: Déboguer cette application avec les paramètres de sécurité sélectionnés (je choisis celui-ci). Au démarrage du débogage, je reçois une demande d'autorisation de type 'System.Security.Permissions.SecurityPermission, mscorlib, Version = 4.0.0.0, Culture = neutre, PublicKeyToken = b77a5c561934e089' échouée.

Lors de l'installation, l'application sera installée mais rien ne se passe au démarrage. Sur un autre ordinateur, un bla bla a cessé de fonctionner (utilitaire de lancement) s'affichera.

OS: Windows 7.

Avec quelques expériences, j'ai découvert que l'ajout du drapeau UnmanagedCode au SecurityPermission a résolu le problème. Pourquoi une simple application WPF (un monde de Hello fraîchement créé) a-t-elle besoin d'appeler du code non géré? C'est un trou de sécurité aussi grand qu'un volcan.

Merci pour tout soupçon

+0

J'ai trouvé un pas si bonne solution: j'ai changé les paramètres de sécurité personnalisés et Copier a collé les autorisations de (intranet local) dans le app.manifest. J'ai changé le securitypermission à: . Cela semble être un trou de sécurité: le drapeau "AllFlags". C'est juste un bonjour WPF. Pourquoi dans le diable a-t-il même besoin d'une autorisation de sécurité? – yonexbat

+1

Enfin trouvé le drapeau pour SecurityPermission. Le drapeau manquant était UnmanagedCode. Pourquoi est-ce qu'un WPF hello world doit appeler unmanagedCode? – yonexbat

Répondre

4

retard à la fête, mais voici ce que j'ai trouvé (tout en trébuchant sur même problème).

Il semble que WPF Window nécessite la permission UnmanagedCode. Extrait de Pro WPF 4.5 in C#: Windows Presentation Foundation in .NET 4.5 par Matthew MacDonald.

ClickOnce and Partial Trust


Et, voici la trace de la pile d'exception, lorsque l'application WPF déployée via ClickOnce en confiance partielle est exécuté. Notez l'appel à DemandUnmanagedCode fonction de SecurityHelper du constructeur de Window:

InnerException: System.Security.SecurityException 
     Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
     Source=mscorlib 
     StackTrace: 
      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
      at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 
      at System.Security.CodeAccessPermission.Demand() 
      at MS.Internal.SecurityHelper.DemandUnmanagedCode() 
      at System.Windows.Window..ctor() 
      at WPFClickOnceDeploySample.MainWindow..ctor() 

Et, voici la pleine StackTrace:

System.Reflection.TargetInvocationException was unhandled 
    Message=Exception has been thrown by the target of an invocation. 
    Source=mscorlib 
    StackTrace: 
     at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) 
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) 
     at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
     at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
     at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
     at System.Activator.CreateInstance(Type type, Object[] args) 
     at CreateInstance(Type type, Object[] arguments) 
     at System.Xaml.Schema.SafeReflectionInvoker.CreateInstance(Type type, Object[] arguments) 
     at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments) 
     at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args) 
     at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args) 
     at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx) 
     at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property) 
     at System.Xaml.XamlWriter.WriteNode(XamlReader reader) 
     at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack``1 stack, IStyleConnector styleConnector) 
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
     at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 
     at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 
     at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc) 
     at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties) 
     at System.Windows.Application.DoStartup() 
     at System.Windows.Application.<.ctor>b__1(Object unused) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.DispatcherOperation.InvokeImpl() 
     at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Windows.Threading.DispatcherOperation.Invoke() 
     at System.Windows.Threading.Dispatcher.ProcessQueue() 
     at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
     at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
     at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
     at System.Windows.Application.RunDispatcher(Object ignore) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run(Window window) 
     at System.Windows.Application.Run() 
     at WPFClickOnceDeploySample.App.Main() 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) 
     at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 
     at System.Activator.CreateInstance(ActivationContext activationContext) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.Security.SecurityException 
     Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
     Source=mscorlib 
     StackTrace: 
      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
      at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 
      at System.Security.CodeAccessPermission.Demand() 
      at MS.Internal.SecurityHelper.DemandUnmanagedCode() 
      at System.Windows.Window..ctor() 
      at WPFClickOnceDeploySample.MainWindow..ctor() 
     InnerException: 
+0

Je travaille maintenant pour une grande entreprise maintenant et le déploiement ClickOnce n'y est pas utilisé. Les applications Windows8 rendront ClickOnce obsolète? Eh bien, la SP change parfois de stratégie comme des sous-vêtements. – yonexbat

+0

@yonexbat Je ne vois pas comment Windows8 rend obsolète ClickOnce, Windows8 store est totalement différent de ClickOnce ... –

Questions connexes