小编Ted*_*ord的帖子

有没有理由为什么用XmlInclude修饰的基类在序列化时仍会抛出类型未知异常?

我将简化代码以节省空间,但所呈现的内容确实说明了核心问题.

我有一个类,它有一个基类型的属性.有3个派生类可以分配给该属性.

如果我将任何派生类分配给容器并尝试序列化容器,则XmlSerializer会抛出可怕的:

"不期望类型x.使用XmlInclude或SoapInclude属性指定静态未知的类型."

但是我的基类已经用该属性修饰,所以我认为必须有一个额外的"隐藏"要求.

真正奇怪的是,默认的WCF序列化程序对此类层次结构没有任何问题.

Container类

[DataContract]
[XmlRoot(ElementName = "TRANSACTION", Namespace = Constants.Namespace)]
public class PaymentSummaryRequest : CommandRequest
{
    [DataMember]
    public PaymentSummary Summary { get; set; }

    public PaymentSummaryRequest()
    {
        Mechanism = CommandMechanism.PaymentSummary;
    }
}
Run Code Online (Sandbox Code Playgroud)

基类

[DataContract]
[XmlInclude(typeof(xPaymentSummary))]
[XmlInclude(typeof(yPaymentSummary))]
[XmlInclude(typeof(zPaymentSummary))]
[KnownType(typeof(xPaymentSummary))]
[KnownType(typeof(yPaymentSummary))]
[KnownType(typeof(zPaymentSummary))]
public abstract class PaymentSummary
{     
}
Run Code Online (Sandbox Code Playgroud)

派生类之一

[DataContract]
public class xPaymentSummary : PaymentSummary
{
}
Run Code Online (Sandbox Code Playgroud)

序列化代码

var serializer = new XmlSerializer(typeof(PaymentSummaryRequest));
serializer.Serialize(Console.Out,new PaymentSummaryRequest{Summary = new xPaymentSummary{}});
Run Code Online (Sandbox Code Playgroud)

例外

System.InvalidOperationException:生成XML文档时出错.---> System.InvalidOperationException:不期望类型为xPaymentSummary.使用XmlInclude或SoapInclude属性指定静态未知的类型.在

Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterPaymentSummaryRequest.Write13_PaymentSummary(String n,String ns,PaymentSummary o,Boolean isNullable,Boolean needType)at at …

.net c# xml-serialization

42
推荐指数
1
解决办法
5万
查看次数

绑定到WPF中的祖先

我在一个程序集中有一个窗口,它有一个TextBlock控件,我想绑定到一个类的属性的值,该类是该窗口父窗口的DataContext的属性.用作DataContext的类仅在第二个程序集中定义.我的问题是我需要在绑定语句中将Type指定为Type.我可以只使用两个程序集之间通用的DataContext属性的类型,还是需要使用DataContext的类型?

以下是我认为它应该如何工作的原型,但因为它不是我对某事感到困惑:)

装配#1
窗口

<TextBlock 
    Text="{Binding RelativeSource={RelativeSource 
        AncestorType={x:Type client:Client}}, Path=Name }"/>
Run Code Online (Sandbox Code Playgroud)

程序集#2
应用程序外壳

class Shell 
{
     public Client Client { get { return client; } set { client = value; } }
     OnStartup()
     {
          NavigationWindow window = new NavigationWindow();
          window.DataContext = this;
          window.Navigate(GetHomeView());
     }
}
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf

27
推荐指数
1
解决办法
3万
查看次数

Azure Cosmos DB - Mongo API是否支持聚合

我希望使用cosmosdb来存储以文档为中心的设计中布置的时间序列数据.使用官方的mongodb驱动程序,我试着写一些简单的聚合语句; 但是,我收到的错误表明$ unwind和$ group不受支持.鉴于cosmosdb被吹捧为mongodb的替代品,我错过了一个步骤,或者聚合不是支持的功能.

retrieve.Aggregate().Unwind(i => i.Observations).Group(new BsonDocument {
        {"_id", "$Observations.Success"},
        {"avg", new BsonDocument{
        {"$avg", "$Observations.Duration"}
        }}
    }).ToList();
Run Code Online (Sandbox Code Playgroud)

c# mongodb mongodb-.net-driver azure-cosmosdb

8
推荐指数
2
解决办法
1377
查看次数

如何为Docker窗口容器定义反向代理

我在Windows 10周年纪念版上运行了一个docker windows容器,我希望将IIS设置为容器的反向代理.根据https://blogs.technet.microsoft.com/virtualization/2016/05/25/windows-nat-winnat-capabilities-and-limitations/它似乎表明这是不可能的,因为它不可能引用内部NAT范围使用本地主机.这会留下动态分配的IP地址,只能在运行映像后通过运行docker inspect命令来发现.我希望有一种更有效的方式让我忽略.

docker

7
推荐指数
2
解决办法
3293
查看次数

如何在 Kusto 时间表上缩放数据系列

我想在时间图上缩放数据系列,以便它与其他系列可见。前两个系列代表成功和失败requests,第三个系列代表customEvent尝试纠正自身的应用程序。所有三个系列都被绘制出来,但由于幅度的相对差异,重启系列本质上是一条在 0 处的线。操作员ysplit选项 的文档render表明这axes将提供我正在寻找的内容,但似乎没有任何值影响图表。

requests
| where timestamp > ago(3d) and name has "POST /v1/validation"
| union customEvents |  where timestamp > ago(3d)
| extend Event=case(itemType == 'request' and success == "True", "Succeeded", itemType == "request" and success == "False", "Failed", "Restarted")
| summarize Count=count() by Event, bin(timestamp, 1h)
| render timechart
Run Code Online (Sandbox Code Playgroud)

这是使用 Restarted 系列渲染的时间图,但桶中的最高数字是 2,因此它本质上是原点处的一条平线。

Kusto 时间表

更新 5/3

UX 客户端是 Azure 门户的 Application Insights Analytics 小部件。

azure azure-application-insights azure-data-explorer

7
推荐指数
1
解决办法
2664
查看次数

通过CodeDomProvider使用AssemblyCopyrightAttribute或AssemblyCompanyAttribute时编译错误

我认为正在进行一些愚蠢的事情,因为其余的汇编级别属性可以包含在内,但无论何时AssemblyCopywriteAttribute或者AssemblyCompanyAttribute声明它都会导致CS0116和CS1730错误.鉴于代码不包含任何方法声明,我没有看到CS0116是如何适用的,并且没有散布的类型定义,因此不确定CS1730是如何适用的.

错误

Error Number: CS0116
Error Text: A namespace cannot directly contain members such as fields or methods

Error Number: CS1730
Error Text: Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations
Run Code Online (Sandbox Code Playgroud)

源文件:

using System;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: CLSCompliant(false)]
[assembly: AssemblyCompany("My Company")]; // this results in a compile time error
[assembly: Guid("9d8271d9-957f-46dc-bcc6-1055137b4fad")]
[assembly: AssemblyTitle("CCDA MAP")]
[assembly: AssemblyDescription("The …
Run Code Online (Sandbox Code Playgroud)

.net codedom c#-4.0

6
推荐指数
1
解决办法
1409
查看次数

强制将项目引用包含在netstandard nuget包中

我有一个netstandard项目,其中包括两个项目参考。Visual Studio 2017正在用于构建nukpg。构建项目时,生成的nupkg仅包含该项目生成的程序集,并将两个项目引用列为nuget依赖项。有没有一种方法可以强制包装将那些程序集包含为lib文件?

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <RootNamespace>Verifier.Observations.DevOps.Health</RootNamespace>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <VersionPrefix>1.0.1</VersionPrefix>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
    <ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System.ComponentModel.Composition"/>
    <Reference Include="System.Net.Http" />
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

更新现在 根据来自@ alexgiondea-msft的反馈,使用以下命令根据需要创建软件包

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <VersionPrefix>1.0.1</VersionPrefix>
    <TargetFramework>net462</TargetFramework>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <NuspecFile>Verifier.Observations.DevOps.Health.Nuspec</NuspecFile>
   <NuspecProperties>version=$(VersionPrefix);id=$(MSBuildProjectName);author=$(Authors);copy=$(Copyright);iconUrl=$(PackageIconUrl)</NuspecProperties>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\Verifier.Observations.Aspects\Verifier.Observations.Aspects.csproj" />
    <ProjectReference Include="..\Verifier.Observations\Verifier.Observations.csproj" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System.ComponentModel.Composition" />
    <Reference Include="System.Net.Http" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

核子

<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <iconUrl>$iconUrl$</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Inspect automation service to ensure it is up and operational</description>
    <releaseNotes></releaseNotes> …
Run Code Online (Sandbox Code Playgroud)

nuget-package visual-studio-2017 .net-standard

5
推荐指数
2
解决办法
1559
查看次数

访问IsolatedStorageBackingStore时出现HRESULT 0X80131468的原因

我面临的情况是我在W2k3服务器上运行的ASP.NET Web服务(.NET 3.5),该服务器使用CacheManager/IsolatedStorage存储来存储持久化状态变量.在我们更改物理机器之前,此配置已经运行了很长时间.现在,当访问该值的代码运行时,它会抛出IsolatedStorageException(在下面发布).据我所知,用户/程序集存储是正在访问的内容,执行用户是本地管理员组的成员.有没有人建议缺少什么特权?

错误

无法创建商店目录.(HRESULT异常:0x80131468)

堆栈跟踪

键入:Microsoft.Practices.ObjectBuilder2.BuildFailedException.错误:当前构建操作(构建密钥构建密钥[Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager,缓存管理器])失败:无法创建商店目录.(来自HRESULT的异常:0x80131468)(策略类型为ConfiguredObjectStrategy,索引2).跟踪:位于Microsoft.Practices的Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator定位器,ILifetimeContainer生命周期,IPolicyList策略,IStrategyChain策略,Object buildKey,Object existing)上的Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context). Microsoft的ObjectBuilder2.Builder.BuildUp [TTypeToBuild](IReadWriteLocator定位器,ILifetimeContainer生命周期,IPolicyList策略,IStrategyChain策略,Object buildKey,Object existing).1.CreateDefault() at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager() at Ept.Commands.SettlementCommand.BeginSettlement() in c:\Projects\EPT\Ept.Framework.Services\Commands\SettlementCommand.cs:line 102 at Ept.Commands.SettlementCommand.ExecuteKernel(SettlementRequest request) in c:\Projects\EPT\Ept.Framework.Services\Commands\SettlementCommand.cs:line 188 at Ept.Command2.Execute(TRequest请求)在c:\ Projects\EPT\Ept.Framework.Services\Commands\Command.cs:第79行.ExecutionStrategyTypeName:ConfiguredObjectStrategy ExecutingStrategyIndex:2 BuildKey:Build Key [Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager ,缓存管理器]类型:System.IO.IsolatedStorage.IsolatedStorageException.错误:无法创建商店目录.(来自HRESULT的异常:0x80131468).跟踪:位于System.IO.IsolatedStorage上System.IO.IsolatedStorageStorageSilerageFile.GetRootDir(IsolatedStorageScope范围)中System.IO.IsolatedStorage.IsolatedStorageFile.InitGlobalsNonRoamingUser(IsolatedStorageScope范围)的System.IO.IsolatedStorage.IsolatedStorageFile.nGetRootDir(IsolatedStorageScope范围)处. System.IO.IsolatedStorage中的.SsolatedStorageFile.GetGlobalFileIOPerm(IsolatedStorageScope范围).2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory2.在Microsoft.Practices.EnterpriseLibrary的Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerAssembler.Assemble(IBuilderContext context,CacheManagerDataBase objectConfiguration,IConfigurationSource configurationSource,ConfigurationReflectionCache reflectionCache)上创建(IBuilderContext上下文,String name,IConfigurationSource配置源,ConfigurationReflectionCache reflectionCache). Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) at Microsoft.Practices.EnterpriseLibrary.Caching.CacheManagerCustomFactory.Create(IBuilderContext context, CacheManagerDataBase objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory2.在Microsoft的Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedCustomFactory`2.CreateObject(IBuilderContext context,String name,IConfigurationSource configurationSource,ConfigurationReflectionCache reflectionCache)上创建(IBuilderContext …

c# enterprise-library isolatedstorage

4
推荐指数
1
解决办法
5488
查看次数

如何从.NET中的X509Certificate2中提取AuthorityKeyIdentifier

我正在寻找一种从X509Certificate2实例中提取AuthorityKeyIdentifier扩展的方法.我没有看到任何内置支持,但由于Windows可以正确构建证书链,我知道功能必须存在于某种程度.如果答案是推送DER解析器,是否有可以引用的良好实现?

c# x509certificate2 x509

4
推荐指数
1
解决办法
4422
查看次数

如何在键/值对的json数组上使用mvexpand

我的appInsights遥测中有一个自定义属性,它是键/值对的json数组。我想做的是投射出那个键/值对,看来一起使用parsejsonmvexpand就是实现这一点的方法。但是,我似乎缺少了一些东西。我表达式的最终结果是一个名为type的列,它是原始的json。尝试将任何属性添加到表达式将导致一个空列。

Json编码的属性

[{"type":"text/xml","count":1}]
Run Code Online (Sandbox Code Playgroud)

空气质量指数

requests 
 | project customDimensions 
 | extend type=parsejson(customDimensions.['Media Types'])
 | mvexpand bagexpansion=array type 
Run Code Online (Sandbox Code Playgroud)

更新6/30/17

如下图所示,要回答EranG的问题,请在将属性投影为列时输出我的请求。

在此处输入图片说明

azure-application-insights ms-app-analytics

4
推荐指数
1
解决办法
2846
查看次数