草庐IT

reference-type

全部标签

c# - 如何解决 '...is a ' type', which is not valid in the given context'? (C#)

以下代码会产生错误:Error:'CERas.CERAS'isa'type',whichisnotvalidinthegivencontext为什么会出现这个错误?usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceWinApp_WMI2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){

c# - 没有无参数构造函数的类型的 Activator.CreateInstance(Type)

这个问题在这里已经有了答案:CreatinginstanceoftypewithoutdefaultconstructorinC#usingreflection(4个答案)关闭9年前。阅读工作中的现有代码,我想知道这怎么能行得通。我在程序集中定义了一个类:[Serializable]publicclassA{privatereadonlystring_name;privateA(stringname){_name=name;}}在另一个程序集中:publicvoidf(Typet){objecto=Activator.CreateInstance(t);}和那个简单的调用f(typeo

c# - 如何解决错误 :the type does not appear to implement microsoft. practices.servicelocation.iservicelocator?

我是MVC的新手,我正在关注“AdamFreeman的PROASP.NETMVC4”。我目前正在研究它的第6章。我正在学习如何使用MVC4中的Ninject进行依赖注入(inject)。我已经按照书中的描述创建了应用程序。现在我不明白为什么会出现以下错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator这是我的Controller代码:publicclassHomeController:Controller{privateProduct[]products={newProduct{Name="Kayak",Cate

c# - 错误 : Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

我正在尝试使用该控件从.ascx设置我的.ascx控件的属性。所以在我的一个包含此控件的.aspx中,我有以下代码试图设置我的嵌入式.ascx的ItemsList属性:Itemitem=GetItem(itemID);myUsercontrol.ItemList=newList().Add(item);我尝试设置的.ascx中的属性如下所示:publicListItemsList{get{returnthis.itemsList;}set{this.itemsList=value;}}错误:无法将类型“void”隐式转换为“System.Collections.Generic.List

c# - x :Type not found in user control library

我正在尝试在WPF用户控件库项目中创建一个ResourceDictionary。当我添加以下样式时:我收到一条错误消息:Thetype'x:Type'wasnotfound.Verifythatyouarenotmissinganassemblyreferenceandthatallreferencedassemblieshavebeenbuilt.我将x声明为:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"当我在WPF应用程序项目中而不是在UserControl库项目中创建资源字典时,这会起作用。知道为什么吗?

C# 泛型 : Simplify type signature

这个问题在这里已经有了答案:GenericswithGenericParametersandAbstractclass(4个答案)关闭9年前。如果我有一个看起来像这样的通用Item类:abstractclassItem{}还有一个看起来像这样的项目容器:classContainerwhereTItem:Item{}既然TItem依赖于T,是否可以简化Container的类型签名,使其只接受一个类型参数?我真正想要的是这样的:classContainerwhereTItem:Item//thisdoesn'tactuallywork,becauseItemtakesatypeparame

c# - Newtonsoft.Json 导致序列化发生两次导致 Reference.cs 中的重复定义

我有一个具有服务引用的项目Common。添加对Newtonsoft.json(Version6.0.2的引用后到具有服务引用和可序列化类ChatLine的同一项目(Common)[Serializable]publicclassChatLine{[JsonProperty("L")]publicstringLineId{get;set;}[JsonProperty("CT")]publicDateTimeConversationTimeInUtc{get;set;}[JsonProperty("S")]publicstringSenderId{get;set;}[JsonPropert

c# - Entity Framework 表拆分 : not in the same type hierarchy/do not have a valid one to one foreign key relationship

我正在使用EntityFramework6和代码优先方法,我希望将两个实体放在同一个表中。我做错了什么?[Table("Review")]publicclassReview{publicintId{get;set;}publicPictureInfoPictureInfo{get;set;}publicintPictureInfoId{get;set;}}[Table("Review")]publicclassPictureInfo{[Key,ForeignKey("Review")]publicintReviewId{get;set;}publicReviewReview{get;s

c# - VS2010 : Warning on add project reference to Silverlight project from . 网络项目

在VS2010、Silverlight4、.NET4中,我有一个WCF服务和一个Silverlight应用程序,Silverlight不是通过添加服务引用而是通过共享契约(Contract)访问类。自然地,这意味着我在Silverlight类库中有契约(Contract),并且该服务有对该库的项目引用。奇怪的是,这会导致引用上出现/!\图标和警告:无法引用项目“SilverlightClassLibrary1”。引用的项目针对不同的框架系列(Silverlight)但是,引用工作正常(我可以在我的Silverlight应用程序中使用该界面)并且构建良好。这是一个错误吗?我的猜测是肯定的

c# - 是否可以将 Type.GetType 与动态加载的程序集一起使用?

假设我有这么一小段代码:publicstaticvoidLoadSomething(Typet){vart1=Type.GetType(t.AssemblyQualifiedName);vart2=t.Assembly.GetTypes().First(ta=>ta.AssemblyQualifiedName==t.AssemblyQualifiedName);}发生的情况是t1为null而t2为notnull。我很困惑,因为如果我这样调用它......LoadSomething(typeof(SomeObject));然后两者都为空,但我实际做的更像是这样(不是真的,这被大大简化了,