问题:

我正在编写一个返回JSON的代码的单元测试。 它返回的类型是匿名类型,所以我想验证它上面的值我只是将对象转换为dynamic来做我的断言。

但是,当我这样做时,我的构建失败但我没有任何错误消息。 我能够在新的单元测试项目中使用非常简单的代码重现这一点:

[TestMethod]
public void TestMethod1()
{
    var obj = new { someValue = true };

    dynamic asDynamic = obj;

    Assert.IsTrue(asDynamic.someValue);
}

请参阅下面的构建失败的屏幕截图

建立失败

当我注释掉断言时,构建成功:

在没有断言的情况下构建成功

相比之下,我在LinqPad 5 beta(使用Roslyn编译器)中运行了以下代码并且没有任何问题:

var obj = new { someValue = true };
dynamic asDynamic = obj;
Console.WriteLine((asDynamic.someValue == true).ToString());

真正

这里发生了什么? 由于错误没有显示我不能说,如果我使用的是dynamic ,不正确的,或者如果它不能找到超载用于IsTrue()的,因为dynamic ,或者如果这是在编译器中的错误(虽然我非常怀疑这一点,但我没有任何证据证明我的代码有问题)。

关于过载问题,我尝试了Assert.IsTrue((bool)asDynamic.someValue); 但构建仍然失败,仍然没有错误消息。

根据Per @ RonBeyer的评论,我也尝试了更多的演员,如下所示无济于事:

    dynamic asDynamic = (dynamic)obj;
    Assert.IsTrue(((dynamic)asDynamic).someValue);

    Assert.IsTrue((bool)asDynamic.somevalue);

经过仔细检查,我发现输出窗口中列出了一个错误:

c:… \\ DynamicBuildFailTest \\ UnitTest1.cs(16,33,16,42):错误CS0656:缺少编译器所需的成员’Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’

好的,VS2013更善于报告错误,我会根据这些搜索:

在此输入图像描述

好的, 添加对Microsoft.CSharp的引用修复了构建错误 ,但我会将此问题保持打开状态,因为它可能是VS2015的问题(在我看来)应该解决。

I was writing a unit test on a piece of code that returned JSON.The type that it returns is an anonymous type, so I thought to verify the values on it I’d just cast the object to a dynamic to do my assertions.However, when I do that, my build fails but I don’t have any error messages.I was able to reproduce this with very simple code in a new Unit Test Project:See below for a screenshot of the build failingThe build succeeds when I comment out the assertion though:In contrast, I ran the following code in LinqPad 5 beta (which uses the Roslyn compiler) and had no issues:TrueWhat’s going on here?Since the error isn’t showing I can’t tell if I’m using dynamic incorrectly, or if it can’t find the overload to use for IsTrue() because of the dynamic , or if this is a bug in the compiler (though I highly doubt this, I don’t have any evidence that there’s something wrong with my code).Regarding the overload issue, I tried Assert.IsTrue((bool)asDynamic.someValue);but the build still fails, still no error message.Per @RonBeyer’s comment, I had also tried more casting such as below to no avail:Upon closer inspection, I found that there was an error listed in the Output window:c:…\\DynamicBuildFailTest\\UnitTest1.cs(16,33,16,42): error CS0656: Missing compiler required member ‘Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create’Okay, VS2013 is better at reporting the errors, I will search based on those:Okay, adding a reference to Microsoft.CSharp fixed the build error , but I will leave this question open because it’s presumably an issue with VS2015 that (in my mind) should be resolved.

问题:

我正在使用Web API 2,当我在本地方框上使用IIS 7.5向我的API方法发送POST时,我收到以下错误。

The inline constraint resolver of type 'DefaultInlineConstraintResolver' was unable to resolve the following inline constraint: 'string'.

Line 21: GlobalConfiguration.Configuration.EnsureInitialized();

我的API都不能使用IIS。 但是,我能够使用IIS Express在Visual Studio中运行我的API项目并成功对我的登录API进行POST,但是当我尝试向另一个API调用发出GET请求时,我得到约束解析器错误。

为了解决这个问题,我在Visual Studio中创建了一个全新的Web API 2项目,并开始一次一个地将现有API导入到新项目中并运行它们以确保它们正常工作。 在这个新项目中使用IIS Express,我得到了与现有API项目相同的结果。

我在这里错过了什么? 即使有一个全新的项目,我也无法在没有遇到这个约束解析器问题的情况下发出GET请求。

I’m using Web API 2 and I’m getting the following error when I send a POST to my API method using IIS 7.5 on my local box.None of my APIs work using IIS.However, I’m able to run my API project in Visual Studio using IIS Express and successfully make a POST to my login API, but when I try and make a GET request to another API call, I get the constraint resolver error.In order to troubleshoot this, I created a brand new Web API 2 project in Visual Studio and started importing the existing APIs into the new project one at a time and running them to ensure they work.Using IIS Express with this new project, I get the same exact results as I did with my existing API project.What am I missing here?Even with a brand new project I’m not able to make GET requests without running into this constraint resolver issue.

问题:

我正在使用Entity Framework 4.1中引入的DbContext和Code First API。

数据模型使用基本数据类型,如stringDateTime 我在某些情况下使用的唯一数据注释是[Required] ,但这不在任何DateTime属性上。 例:

public virtual DateTime Start { get; set; }

DbContext子类也很简单,看起来像:

public class EventsContext : DbContext
{
    public DbSet<Event> Events { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Event>().ToTable("Events");
    }
}

初始化程序将模型中的日期设置为今年或明年的合理值。

但是,当我运行初始化程序时,我在context.SaveChanges()收到此错误:

将datetime2数据类型转换为日期时间数据类型会导致超出范围的值。 该语句已终止。

我不明白为什么会发生这种情况,因为一切都很简单。 我也不确定如何解决它,因为没有edmx文件可以编辑。

有任何想法吗?

I’m using the DbContext and Code First APIs introduced with Entity Framework 4.1.The data model uses basic data types such as string and DateTime .The only data annotation I’m using in some cases is [Required] , but that’s not on any of the DateTime properties.Example:The DbContext subclass is also simple and looks like:The initializer sets dates in the model to sensible values in either this year or next year.However when I run the initializer, I get this error at context.SaveChanges() :The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.The statement has been terminated.I don’t understand why this is happening at all because everything is so simple.I’m also not sure how to fix it since there is no edmx file to edit.Any ideas?

问题:

为什么我会收到以下错误?

只有在使用/ unsafe进行编译时才会出现不安全的代码?

我在C#和Visual Studio 2008中工作,在Windows CE上进行编程。

Why do I get the following error?Unsafe code may only appear if compiling with /unsafe”?I work in C# and Visual Studio 2008 for programming on Windows CE.

问题:

我有一个Windows服务解决方案,我正在尝试在VS2010中向Hermes(Opensource ebms消息服务器)Web服务添加服务引用。

我可以使用它的URL找到Web服务,但是当我尝试填充服务引用时,我在Visual Studio中遇到以下错误:

Error 8 Custom tool error: Failed to generate code for the service reference 'testService'.  Please check other error and warning messages for details. C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler


Warning 6 Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 7 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:binding[@name='EbmsSoapHttpStatusQuery']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:service[@name='EbmsMessageStatusQuery']/wsdl:port[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

Warning 5 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://service.ebms.edi.cecid.hku.hk/' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://service.ebms.edi.cecid.hku.hk/']/wsdl:portType[@name='EbmsStatusQuery'] C:\Users\Admin\documents\visual studio 2010\Projects\MyProject\MyProject.MessageHandler\Service References\testService\Reference.svcmap 1 1 MyProject.MessageHandler

一些调查似乎表明,由于没有对目录(可能是c:\\ windows \\ temp)的权限,svcutil.exe无法构建代理。 我已尝试分配各种访问权限,但我不确定哪个用户需要该权限,或者它只是一个红色的鲱鱼。

任何想法将不胜感激。

谢谢

I have a Windows Service Solution and am trying to add a service reference to a Hermes(Opensource ebms message server) Web Service in VS2010.I can find the Web Service using it’s URL, but when I try and populate the Service reference I get the following errors in Visual Studio:Some investigation seemed to suggest it is due to svcutil.exe not been able to build the proxys due to not having permissions to a directory (possibly c:\\windows\\temp).I have tried assigning various access permissions, but I am not really sure which user needs the permission, or if it is just a red herring.Any ideas would be greatly appreciated.Thanks