0

我有一个在模拟器中本地运行的云服务 Web 角色项目,但在部署时不运行。给出的错误如下:

[ArgumentNullException: Value cannot be null.
Parameter name: connectionString]
   Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(String connectionString) in e:\projects\azure-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\Common\CloudStorageAccount.cs:344
   Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.GetTable() in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:66
   Candor.WindowsAzure.Storage.Table.CloudTableProxy`1.Get(String partitionKey, String rowKey) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor.WindowsAzure\Storage\Table\CloudTableProxy.cs:117
   Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_Configuration() +218
   Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.get_IsInfoEnabled() +9
   Common.Logging.Factory.AbstractLogger.Info(Object message) in c:\_oss\common-logging\src\Common.Logging.Core\Logging\Factory\AbstractLogger.cs:503
   Candor.Configuration.Provider.ProviderCollection`1.SetActiveProvider(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderCollection.cs:169
   Candor.Configuration.Provider.ProviderResolver`1.AppendActive(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderResolver.cs:77
   SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.InitProviders() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:23
   SHM.PublicMvcWeb.App_Start.ProviderBootstrapper.PostStartup() in c:\Users\micha_000\Documents\Git-Repos\shm-main\SHM.PublicMvcWeb\App_Start\ProviderBootstrapper.cs:18

您可以在 github 上的堆栈跟踪中查看相关行的代码。

https://github.com/michael-lang/candor-common/

CloudTableProxy 中导致错误的行是:

            if (String.IsNullOrWhiteSpace(_connectionName))
                throw new InvalidOperationException("The Cloud ConnectionName has not been configured.");
            if (_account == null)
                _account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting(_connectionName));

由于它没有抛出自定义错误“尚未配置云连接名称。”,这告诉我传递给 CloudConfigurationManager.GetSetting 的 _connectionName 不为空。所以 CloudConfigurationManager 是为提供的名称返回 null 的调用。鉴于此名称在本地运行时确实返回了一个值,我不确定为什么在部署到我的云 Web 角色时找不到它。如果连接名称输入为拼写错误,那么它也无法在本地工作。可以肯定的是,这是我常用的日志配置,命名要使用的连接:

  <common>
    <logging>
      <factoryAdapter type="Candor.WindowsAzure.Logging.Common.Table.CloudTableLoggerFactoryAdapter, Candor.WindowsAzure.Logging.Common">
        <arg key="connectionName" value="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" />
      </factoryAdapter>
    </logging>
  </common>

对于使用相同 Candor.Common 组件的云服务 Web 角色,我也有一个完全不同的解决方案,所以我不认为它们是问题所在。

我使用同一台笔记本电脑来开发这两种解决方案,因此两者都使用 Azure 2.2 工具版本。检查每个解决方案中云服务项目的属性可以验证这一点。

我检查了每个组件和 NuGet 包引用,以确保解决方案中没有版本不匹配。在工作解决方案和此非工作解决方案之间将相同的组件设置为 copy-local=true。它们也具有相同的绑定重定向。虽然这是我最大的问题,但现在已解决,然后才遇到此连接问题。

非工作服务部署配置:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="SHM.AzureService.PublicMvcWeb" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2013-10.2.2">
  <Role name="SHM.PublicMvcWeb">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
      <Setting name="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
      <Setting name="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
      <Setting name="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
      <Setting name="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

我最近还尝试将这些相同的连接名称放在 Web 应用程序的 appsettings 中。这是对 3 年前评论的回应,即他们的代码在 RoleEnvironment.OnStart 之前执行。但是这种尝试仍然会导致同样的错误。

这是尝试的样子:

  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
    <add key="DefaultTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
    <add key="UserTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
    <add key="UserSaltTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
    <add key="UserAuditTableConnection" value="DefaultEndpointsProtocol=https;AccountName=(redacted);AccountKey=(redacted)"/>
  </appSettings>

此错误代码确实在使用 WebActivator 2.0.6 的应用程序启动时运行,而我的工作解决方案使用 WebActivator 2.0.4。但是 WebActivator 的发行说明只显示了从 Debug 到“Retail”的编译更改以及两个版本之间的许可证更改,而这些更改是一年前的。

如果时间是问题,我还尝试在错误调用之前添加一个 Thread.Sleep(1000) ,但它也不起作用,所以我要删除它。

using System.Threading;
using Candor.Configuration.Provider;
using Candor.Security;
using Candor.Security.Cryptography;
using Candor.Security.Web;

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PreStartup")]
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(StopHarassingMe.PublicMvcWeb.App_Start.ProviderBootstrapper), "PostStartup")]

namespace SHM.PublicMvcWeb.App_Start
{
    public class ProviderBootstrapper
    {
        public static void PreStartup()
        {
        }
        public static void PostStartup()
        {
            Thread.Sleep(1000); //let RoleEnvironment finish startup first or connectionstrings are not available.
            InitProviders();
        }

        private static void InitProviders()
        {
            ProviderResolver<HashProvider>.Configure()
                .AppendActive(new SHA2HashProvider("sha2") { IsObsolete = false, SaltModifier = "" });
        }
    }
}

这是在工作和非工作解决方案中配置的第一个提供程序。

以下是 Web 应用程序错误使用的包的列表:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net45" />
  <package id="Candor.Core" version="1.4.1.0" targetFramework="net45" />
  <package id="Candor.jQuery.AutoAsync" version="4.0.0.50129" targetFramework="net45" />
  <package id="Candor.Security" version="2.4.0.0" targetFramework="net451" />
  <package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" />
  <package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" />
  <package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" />
  <package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" />
  <package id="Candor.WindowsAzure" version="1.3.0.0" targetFramework="net451" />
  <package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" />
  <package id="Common.Logging" version="2.2.0" targetFramework="net45" />
  <package id="Common.Logging.Core" version="2.2.0" targetFramework="net45" />
  <package id="form2js" version="1.0.0.30224" targetFramework="net45" />
  <package id="jQuery" version="2.1.4" targetFramework="net451" />
  <package id="jQuery.UI.Combined" version="1.8.20.1" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.13.1" targetFramework="net45" />
  <package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.3" targetFramework="net451" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net451" />
  <package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net451" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
  <package id="Modernizr" version="2.8.3" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
  <package id="Respond" version="1.4.2" targetFramework="net45" />
  <package id="RestSharp" version="105.0.1" targetFramework="net451" />
  <package id="System.Spatial" version="5.6.0" targetFramework="net451" />
  <package id="T4MVC" version="3.7.4" targetFramework="net45" />
  <package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" />
  <package id="Twilio" version="4.0.3" targetFramework="net451" />
  <package id="Twilio.Mvc" version="3.1.15" targetFramework="net451" />
  <package id="Twilio.TwiML" version="3.3.6" targetFramework="net451" />
  <package id="WebActivatorEx" version="2.0.6" targetFramework="net451" />
  <package id="WebGrease" version="1.6.0" targetFramework="net45" />
  <package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" />
</packages>

我的工作解决方案和非工作解决方案之间存在一些包差异,但我认为这些不适用于错误。我从 MVC 5.0 升级到 5.2.3,升级了 javascript 相关包,以及从 1.2.10 升级到 1.3 的 Candor.WindowsAzure。这似乎是相关的,但唯一的代码更改是替换批量更新方法的实现。

工作解决方案项目包:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net45" />
  <package id="Candor.Core" version="1.4.1.0" targetFramework="net451" />
  <package id="Candor.jQuery.AutoAsync" version="3.5.0.40210" targetFramework="net451" />
  <package id="Candor.Security" version="2.4.0.0" targetFramework="net451" />
  <package id="Candor.Security.AzureStorageProvider" version="2.3.2.0" targetFramework="net451" />
  <package id="Candor.Web.Mvc" version="1.0.3.0" targetFramework="net451" />
  <package id="Candor.Web.Mvc.ErrorHandler" version="1.0.0.0" targetFramework="net45" />
  <package id="Candor.Web.Mvc.Security" version="2.1.0.0" targetFramework="net45" />
  <package id="Candor.WindowsAzure" version="1.2.10.0" targetFramework="net451" />
  <package id="Candor.WindowsAzure.Logging.Common" version="1.1.1.0" targetFramework="net451" />
  <package id="Common.Logging" version="2.2.0" targetFramework="net451" />
  <package id="Common.Logging.Core" version="2.2.0" targetFramework="net451" />
  <package id="form2js" version="1.0.0.30224" targetFramework="net45" />
  <package id="jQuery" version="2.0.3" targetFramework="net45" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" />
  <package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
  <package id="MarkdownSharp" version="1.13.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.Mvc" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.Data" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebPages.WebData" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Data.Edm" version="5.6.0" targetFramework="net45" />
  <package id="Microsoft.Data.OData" version="5.6.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Ajax" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.0.0" targetFramework="net45" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net45" />
  <package id="Modernizr" version="2.7.1" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.8" targetFramework="net45" />
  <package id="SlidesJS" version="3.0.4" targetFramework="net451" />
  <package id="System.Spatial" version="5.6.0" targetFramework="net45" />
  <package id="T4MVC" version="3.7.4" targetFramework="net45" />
  <package id="T4MVCExtensions" version="3.7.4" targetFramework="net45" />
  <package id="WebActivatorEx" version="2.0.4" targetFramework="net45" />
  <package id="WebGrease" version="1.6.0" targetFramework="net451" />
  <package id="WindowsAzure.Storage" version="2.1.0.3" targetFramework="net45" />
</packages>
4

3 回答 3

0

我试图部署为一个网站,只是为了看看会有什么不同。表连接字符串位于 appSettings 中,因为早期尝试解决时间问题,因此尝试网站部署选项(不是云 Web 角色)是有意义的。

这次尝试的错误是

[FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]

[FileNotFoundException: Could not load file or assembly 'Microsoft.WindowsAzure.ServiceRuntime, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
   Candor.WindowsAzure.Logging.Common.Table.CloudTableLogger.WriteInternal(LogLevel level, Object message, Exception exception) +0
   Common.Logging.Factory.AbstractLogger.Info(Object message) in c:\_oss\common-logging\src\Common.Logging.Core\Logging\Factory\AbstractLogger.cs:504
   Candor.Configuration.Provider.ProviderCollection`1.SetActiveProvider(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderCollection.cs:166
   Candor.Configuration.Provider.ProviderResolver`1.AppendActive(T provider) in c:\Users\micha_000\Documents\GitHub\candor-common\Candor\Configuration\Provider\ProviderResolver.cs:75

这很奇怪,因为现在部署到云的另一个工作解决方案 Web 角色将该引用设置为 CopyLocal=false。但是当我在这个非工作解决方案中将其设置为 true 时,它​​开始在网站部署中工作。

接下来,我将此组件设置为 CopyLocal=True 重新部署了云 Web 角色,它现在可以工作了。我不知道为什么在一个项目部署而不是另一个项目部署中需要这样做,虽然这两个项目都要求其他 azure 组件为 CopyLocal=true。

启动速度仍然存在一个挥之不去的问题,但如果我不弄清楚,我会把它留给另一个问题。出于某种原因,这个较小的项目在启动后会进入繁忙/回收循环,但页面会时不时地加载。这很奇怪,因为它在启动时初始化的依赖项较少,即提供程序实例化,每个都写入一个日志条目。

于 2015-06-04T19:54:16.267 回答
0

直截了当的问题是 - CloudConfigurationManager.GetSetting 将从 Cloud Project 设置中读取给定的配置键(如果已定义),否则将回退到实际的项目 App 或 Web 配置。因此,如果您确保它存在于其中一个地方,它应该可以正常工作。当您确认它在本地工作时,即使在部署之后它也应该以完全相同的方式工作。

其他可能发生的情况是,当您有多个用于本地和云部署环境的配置文件时,您用于部署到云中的云配置文件中可能缺少该配置。

于 2015-06-05T06:31:59.677 回答
0

在我的例子中,我使用了 SlowCheetah(NuGet 包)来转换 App.config 文件。在调试中它没有使用转换。使用“root”-config 文件中的调试设置解决了我的问题。

于 2018-06-05T10:54:03.583 回答