none
A privilege that the service requires to function properly does not exist in the service account configuration RRS feed

  • Question

  • We're using report viewer 2008 to show a simple one page report in our winforms app. It works great unless the report is ran too many times (I'm guessing under 100). We end up with the below exception and it requires our app to be restarted in order to solve the issue.

    This appears to happen when calling Invoke on the ReportViewer control. There are three places I call Invoke, but I'd have to add more logging code to determine where. Two of the Invoke calls simply set the ReportViewer visibility, so I doubt they would be a problem. The third place actually handles setting up the report...

    ReportViewerControl.Reset();

    //Extension method GetStream on AppDomain to load embedded rdlc ReportViewerControl.LocalReport.LoadReportDefinition( AppDomain.CurrentDomain.GetStream(ReportNames.FieldSheetSummaryReportRDLC)); ReportViewerControl.LocalReport.DataSources.AddRange(dataSources); ReportViewerControl.LocalReport.SetParameters(parameters); ReportViewerControl.LocalReport.EnableExternalImages = true; ReportViewerControl.RefreshReport();


    Nothing is in the EventLog. Considering this report works fine some number of times, I'm wondering if there could be a memory or handle leak. But on the other hand, the exception message suggests a security issue. So far I've only had one user complain, so I've also toyed with the possibility that something is messed up on that PC. Any ideas on what to look for?

    Message: A privilege that the service requires to function properly does not exist in the service account configuration. You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration. (Exception from HRESULT: 0x80070511)
       at System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(CreateActContextParameters& Params)
       at System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(IDefinitionAppId AppId)
       at System.ActivationContext.CreateFromName(ApplicationIdentity applicationIdentity)
       at System.Deployment.Internal.Isolation.Manifest.CmsUtils.CreateActivationContext(String fullName, String[] manifestPaths, Boolean useFusionActivationContext, ApplicationIdentity& applicationIdentity, ActivationContext& activationContext)
       at System.AppDomain.SetDomainManager(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
       at System.AppDomain.InternalRemotelySetupRemoteDomainHelper(Object[] args)
       at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
       at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)

    Wednesday, April 6, 2016 11:28 PM

All replies

  • I have the exact same issue and never managed to find the cause of this. Would love to understand why this happens.
    Thursday, April 21, 2016 11:34 AM
  • I'm not sure if I have it fixed, but I did look into an issue with ClickOnce that would cause this same error after too many tries at manually checking for updates. We had some users have this happen as well... https://social.msdn.microsoft.com/Forums/windows/en-US/d9183f7e-f5c7-46d0-8bb4-411ad923976c/a-privilege-that-the-service-requires-to-function-properly-does-not-exist-in-the-service-account?forum=winformssetup

    I think a certain type of handle was being used and not disposed by ClickOnce and possibly that same kind of handle was used by ReportViewer. If that's true, I imagine ClickOnce was causing the handle leak and my ReportViewer exception was just a symptom of that problem. I used one of the workarounds to check for ClickOnce updates. I have yet to get any feedback on whether the ReportViewer problem is still there.

    But obviously if you don't use ClickOnce and check for manual updates, it wouldn't be the problem. But, it could be something else in your app that leaks these resources.

    Thursday, April 21, 2016 8:31 PM
  • Well, it doesn't look like my problem is fixed. I'm getting a similar error somewhere else...

    A privilege that the service requires to function properly does not exist in the service account configuration. You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration. (Exception from HRESULT: 0x80070511)
       at System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(CreateActContextParameters& Params)
       at System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(IDefinitionAppId AppId)
       at System.ActivationContext.CreateFromName(ApplicationIdentity applicationIdentity)
       at System.Deployment.Internal.Isolation.Manifest.CmsUtils.CreateActivationContext(String fullName, String[] manifestPaths, Boolean useFusionActivationContext, ApplicationIdentity& applicationIdentity, ActivationContext& activationContext)
       at System.AppDomain.SetDomainManager(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
       at System.AppDomain.InternalRemotelySetupRemoteDomainHelper(Object[] args)
       at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
       at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
       at Microsoft.Reporting.ReportCompiler.CompileReport(CatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ReportSnapshotBase& snapshot)

    Monday, May 9, 2016 8:09 PM
  • I know it's been awhile, but we still have this issue. I was wondering if anyone else has seen it? 

    I did some more checking and I have verified this is definitely related to being deployed via ClickOnce. I don't know what ClickOnce does behind the scenes, but my best guess is some kind of sandboxing/security and it has a leak when used in conjunction with report viewer.

    To test, I created a simple command line app. It uses LocalReport to generate PDF files. No winforms controls at all being used. The rdlc report itself is completely empty. Put this in an infinite loop. Running the app from visual studio it will keep running as long as you want. Deploy with clickonce, and it runs somewhere around 2000 times and then the above error happens.


    Thursday, October 19, 2017 5:23 PM
  • Well after more testing, I found that it's at least partially related to ReportViewer creating a new AppDomain. I created a console app that does an infinite loop of creating an AppDomain, then unloading the AppDomain. Works fine when ran through VS. When deployed with ClickOnce, it got about 16000 loops and then crashed with the previously posted stack trace. Did the same test using VS2012 and .net 4.5 and it had no problems. Must be a bug that has been fixed, so I guess the solution will be for me to upgrade my app.
    • Marked as answer by uler3161 Saturday, October 21, 2017 5:01 AM
    • Unmarked as answer by uler3161 Wednesday, October 25, 2017 2:56 PM
    • Marked as answer by uler3161 Wednesday, October 25, 2017 3:00 PM
    • Unmarked as answer by uler3161 Wednesday, October 25, 2017 8:09 PM
    Thursday, October 19, 2017 6:34 PM
  • Guess I got ahead of myself. This still doesn't work. There is still a memory leak with Report Viewer after upgrading to VS2012, Report Viewer 2012, and .net 4.5 (as well as 4.6.1)

    Is there something wrong with the following code that would cause a leak (but apparently only when it's ran as a ClickOnce app)?...

    Note that TestAppDomain.Test2.rdlc is simply a new RDLC file with no changes. In other words, a blank report.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Reporting.WinForms;
    
    namespace TestAppDomain
    {
        class Program
        {
            static void Main(
                string[] args)
            {
                var count = 0;
                while (true)
                {
                    Console.WriteLine("Exporting: " + count);
                    try
                    {
                        //var domain = AppDomain.CreateDomain("Temp");
                        //AppDomain.Unload(domain);
                        using (var exporter = new PDFExporter())
                        {
                            exporter.Export(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                        break;
                    }
                    count++;
                }
    
                Console.WriteLine("Finished");
                Console.ReadLine();
            }
        }
    
    
        public class PDFExporter : IDisposable
        {
            private const string DeviceInfo =
                "<DeviceInfo>" + "  <OutputFormat>PDF</OutputFormat>" + "  <PageWidth>{0}in</PageWidth>"
                    + "  <PageHeight>{1}in</PageHeight>" + "  <MarginTop>{2}in</MarginTop>"
                    + "  <MarginLeft>{3}in</MarginLeft>" + "  <MarginRight>{4}in</MarginRight>"
                    + "  <MarginBottom>{5}in</MarginBottom>" + "</DeviceInfo>";
    
            public PDFExporter()
            {
            }
    
            private LocalReport LocalReport
            {
                get;
                set;
            }
    
            private IList<byte[]> Streams
            {
                get;
                set;
            }
    
            public IList<byte[]> Export(int retry)
            {
                Streams = new List<byte[]>();
                LocalReport = new LocalReport { EnableExternalImages = true };
    
                Warning[] warnings;
                try
                {
                    LoadDefinitions();
                    SetSubreportProcessing();
                    SetDataSources();
    
                    string[] streamids;
                    string mimeType;
                    string encoding;
                    string filenameExtension;
    
    
                    var bytes = LocalReport.Render("PDF", GetDeviceInfo(), out mimeType, out encoding,
                        out filenameExtension, out streamids, out warnings);
    
                    Streams.Add(bytes);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
    
                    //Note: this was put here for debugging this:
                    //http://codeverge.com/asp.net.ssrs/reportviewer-occasionaly-runing-into-index-was-o/9266
                    var inner = ex.InnerException;
                    while (inner != null)
                    {
                        Console.WriteLine(inner.Message + Environment.NewLine + inner.StackTrace);
                        inner = inner.InnerException;
                    }
    
                    if (retry == 3)
                    {
                        throw;
                    }
    
                    if (LocalReport != null)
                    {
                        LocalReport.ReleaseSandboxAppDomain();
                    }
                    return Export(retry + 1);
                }
    
                PrintWarnings(warnings);
    
                if (LocalReport != null)
                {
                    LocalReport.ReleaseSandboxAppDomain();
                }
    
                return Streams;
            }
    
            private string GetDeviceInfo()
            {
                return string.Format(DeviceInfo, 8.5, 11, 0.25m,
                    0, 0,
                   0.25m);
            }
    
            private void LoadDefinitions()
            {
                LocalReport.ReportEmbeddedResource = "TestAppDomain.Test2.rdlc";
            }
    
            private void PrintWarnings(IEnumerable<Warning> warnings)
            {
                var s = string.Join(Environment.NewLine,
                    warnings.Select(p => p.Code + ": " + p.Message + ", " + p.ObjectName)
                        .ToArray());
    
                if (string.IsNullOrEmpty(s))
                {
                    return;
                }
    
                Console.WriteLine(Environment.NewLine + s);
            }
    
            private void SetDataSources()
            {
            }
    
            private void SetSubreportProcessing()
            {
            }
    
            public void Dispose()
            {
                if (LocalReport != null)
                {
                    LocalReport.Dispose();
                }
            }
        }
    }

    Wednesday, October 25, 2017 8:15 PM
  • For what it is worth we now use Report Viewer 2015 and I dont believe we have any issues with this exception since the switch over.
    • Edited by Pawaw Thursday, October 26, 2017 11:23 AM
    Thursday, October 26, 2017 11:23 AM
  • That might be the path I have to try. I've tried all sorts of different things in code that people have recommended and to no avail. It's either that or run every report in its own process, but I hate that idea.
    Thursday, October 26, 2017 6:00 PM
  • Now I'm using VS2017 with Report Viewer 2015, .NET 4.6.1 x64 build. Problem is still there.

    I was thinking about reporting this as a bug, but I was hoping someone could tell me if there was anything in my example that I'm not doing correctly.

    I have zipped up my test solution HERE if anyone is interested in seeing whether they can reproduce the problem. You'll have to set up a server to deploy via ClickOnce and run the app that way.

    Tuesday, October 31, 2017 2:55 PM
  • I went ahead and created a bug report. As far as I can tell, I'm properly disposing of the LocalReport, so I don't see anything else I could do to fix the problem in my code.

    Bug Report

    Tuesday, October 31, 2017 3:49 PM
  • Hi uler3161,

    Many thanks for the sample project which I have tested on a few machines. Here are my results:

    1. Windows Server 2008 R2 (8 GB RAM): Error occurs after 2518 iterations.
    2. Windows 7 SP1 (32 GB RAM): Error occurs after 1918 iterations.
    3. Windows 10 build 1709: No error observed yet on two different machines. One machine is up to +25000 iterations.

    With the above results in mind I believe this error is related to the ClickOnce implementation in at least build 7601 of windows.

    Which product did you report the bug on? Windows, .net, SQL Reporting? Without knowing I speculate that it should be reported as a windows bug.

    EDIT: I see the bug was reported to the Visual Studio team, so please ignore my last question.
    • Edited by Pawaw Wednesday, November 1, 2017 5:15 PM
    Wednesday, November 1, 2017 5:12 PM
  • Thanks for reproducing the issue.
    Wednesday, November 1, 2017 5:27 PM
  • I have the same issue.
    I deploy a app via ClickOnce, run on many machines Win7 x64 4GB with .Net4.5.1 and ReportViewer 2015.
    When I show a report which use Reporting service, the exception occurs after about serveral hundred times:

    Microsoft.Reporting.WinForms.LocalProcessingException: ローカル レポートの処理中にエラーが発生しました。    ---> Microsoft.Reporting.DefinitionInvalidException: レポート 'C:\Users\...\AppData\Local\Apps\2.0\K15L2KVB.0MJ\HXEOE7RV.HBP\dens..tion_1ff3e0a0e9a10e41_0001.0003_62a82f7a9eaf0940\Report\DailyReport\DynamicDailyReport\DynamicDailyReport.rdlc'
     の定義が無効です。    ---> System.Runtime.InteropServices.COMException: サービスが適切に機能するために必要な特権が、サービス アカウント構成に存在しません。 サービス Microsoft 管理コンソール (MMC) スナップイン (services.msc) とローカル セキュリティ設定 MMC スナップイン (secpol.msc) を使って、サービス構成とアカウント構成を表示することができます。 (HRESULT
     からの例外:0x80070511)
       場所 System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(CreateActContextParameters& Params)
       場所 System.Deployment.Internal.Isolation.IsolationInterop.CreateActContext(IDefinitionAppId AppId)
       場所 System.ActivationContext.CreateFromName(ApplicationIdentity applicationIdentity)
       場所 System.ActivationContext..ctor(ApplicationIdentity applicationIdentity)
       場所 System.Deployment.Internal.Isolation.Manifest.CmsUtils.CreateActivationContext(String fullName, String[] manifestPaths, Boolean useFusionActivationContext, ApplicationIdentity& applicationIdentity, ActivationContext& activationContext)
       場所 System.AppDomain.InitializeDomainSecurity(Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, Boolean generateDefaultEvidence, IntPtr parentSecurityDescriptor, Boolean publishAppDomain)
       場所 System.AppDomain.Setup(Object arg)
       場所 System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
       場所 System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
       場所 System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
       場所 Microsoft.Reporting.ReportCompiler.CreateCompilationTempAppDomain()
       場所 Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
       --- 内部例外スタック トレースの終わり ---
       場所 Microsoft.Reporting.ReportCompiler.CompileReport(ICatalogItemContext context, Byte[] reportDefinition, Boolean generateExpressionHostWithRefusedPermissions, ControlSnapshot& snapshot)
       場所 Microsoft.Reporting.LocalService.GetCompiledReport(PreviewItemContext itemContext, Boolean rebuild, ControlSnapshot& snapshot)
       場所 Microsoft.Reporting.LocalService.CompileReport()
       場所 Microsoft.Reporting.LocalService.Microsoft.Reporting.ILocalProcessingHost.CompileReport()
       場所 Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       --- 内部例外スタック トレースの終わり ---
       場所 Microsoft.Reporting.WinForms.LocalReport.EnsureExecutionSession()
       場所 Microsoft.Reporting.WinForms.LocalReport.GetDefaultPageSettings()
       場所 Microsoft.Reporting.WinForms.ReportViewer.ResetAndGetPageSettings()
       場所 Microsoft.Reporting.WinForms.ReportViewer.ResetPageSettings()
       場所 DensoPackageWindowAP.Report.ReportViewerModel.UpdateReportViewer()

    It means:

    A privilege that the service requires to function properly does not exist in the service account configuration. 
    You may use the Services Microsoft Management Console (MMC) snap-in (services.msc) and the Local Security Settings MMC snap-in (secpol.msc) to view the service configuration and the account configuration. (Exception from HRESULT: 0x80070511

    My app only works fine after restart.
    I found the near time with all of error times, SQL server is raise event "Data File Auto Grow"
    I guess there is issue of memory therefore I have set the limited memory of SQL server is 2 GB and add LOCAL SERVICE account into Performance policy group as this suggestion: https://theitbros.com/event-id-7000-service-control-manager/

    Now I still have not seen error occur.
    I'm not sure it 's resolved issue and why ?
    Please help to follow this topic continue and let me know if you find the solution. 

    Saturday, December 23, 2017 2:26 AM