Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当Windows服务以发布模式托管时,Hangfire服务器无法拾取作业_C#_Windows Services_Hangfire_Badimageformatexception - Fatal编程技术网

C# 当Windows服务以发布模式托管时,Hangfire服务器无法拾取作业

C# 当Windows服务以发布模式托管时,Hangfire服务器无法拾取作业,c#,windows-services,hangfire,badimageformatexception,C#,Windows Services,Hangfire,Badimageformatexception,我在里面托管hangfire服务器,这样当我的ps启动时,hangfire服务器会自动启动并开始执行作业 现在的问题是,当我以调试模式托管我的Windows服务以及共享库(其中包含在调试模式下执行长时间运行的作业的代码)时,一切都正常,即hangfire能够拾取并执行作业 但当我在发布模式下托管Windows服务和共享库时,我会出现以下错误: 无法加载文件或程序集“ClassLibrary1.SharedLibrary”, Version=1.0.0.0,Culture=neutral,Publ

我在里面托管hangfire服务器,这样当我的ps启动时,hangfire服务器会自动启动并开始执行作业

现在的问题是,当我以
调试模式
托管我的Windows服务以及共享库(其中包含在
调试模式
下执行长时间运行的作业的代码)时,一切都正常,即hangfire能够拾取并执行作业

但当我在发布模式下托管Windows服务和共享库时,我会出现以下错误:

无法加载文件或程序集“ClassLibrary1.SharedLibrary”, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'或其 依赖关系。试图加载带有错误代码的程序 格式

我的Windows服务正在
LocalSystem
上运行,我的数据库位于同事的计算机上

代码:

public partial class MyNewService1 : ServiceBase
        {
            private BackgroundJobServer _server;
            private System.Diagnostics.EventLog eventLog1;
            public MyNewService1()
            {
                InitializeComponent();
                eventLog1 = new System.Diagnostics.EventLog();
                if (!System.Diagnostics.EventLog.SourceExists("MySource"))
                {
                    System.Diagnostics.EventLog.CreateEventSource(
                        "MySource", "MyNewLog");
                }
                eventLog1.Source = "MySource";
                eventLog1.Log = "MyNewLog";
                GlobalConfiguration.Configuration.UseSqlServerStorage("connectionstring"); 
            }

            protected override void OnStart(string[] args)
            {
                eventLog1.WriteEntry("In OnStart", EventLogEntryType.Information);
                _server = new BackgroundJobServer();
            }

            protected override void OnStop()
            {
                _server.Dispose();
            }
        }
我从以下参考中获取代码:

在文档中,并没有提到我是否应该在调试/发布模式下托管Windows服务

这是Windows服务还是hangfire问题

更新:我认为问题与此处描述的Windows服务有关,但仍然不走运:


事实上,问题与权限有关,我必须从
LocalSystem
更改为
NetworkService
,以便分配
NT AUTHORITY\SYSTEM
的权限

有了这一点,我已经按照以下链接给出的答案解决了我的问题:


您链接的问题的公认答案描述得非常好。你试过了吗?@Evk是的,我试过了,而且不得不改变账户类型。我已经发布了答案