“像使用一种类型的命名空间”错误 [英] 'namespace used like a type' error
问题描述
codeRS,我想转换一个XAML字符串中使用的库,我发现的此处,但我有创造,将让我使用的库对象的新实例的问题。我已经添加了一个参考图书馆在我的Asp.net项目,我想用它在一个WCF文件。
现在的问题是,每当我尝试实例化一个新的对象,使用new关键字,我得到一个错误,说:
MarkupConverter'是'空间',但用于像一个类型。
下面是我的code,请注意,我创造就像在上面的库链接显示的例子一个新的对象,请帮助:
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Runtime.Serialization;
使用System.ServiceModel;
使用System.Text;
使用System.Web.Services;
使用System.Net.Mail;
使用System.ServiceModel.Activation;
使用System.Data.SqlClient的;
使用MarkupConverter;
命名空间AspPersonalWebsite
{
[的ServiceContract(命名空间=)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)
公共类服务1 //:IService1
{
私人字符串的connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
私人IMarkupConverter markupConverter;
[OperationContract的]
公共字符串convertXAMLToHTML(字符串XAMLtext)
{
字符串的htmlText =;
markupConverter =新MarkupConverter(); / *问题是在这里* /
的htmlText = markupConverter.ConvertXamlToHtml(XAMLtext);
返回的htmlText;
}
}
}
混乱是因为所产生的实际类型是 MarkupConverter.MarkupConverter
,编译器似乎认为你的新MarkupConverter
是试图使用一个命名空间作为一个类型,而不是试图实例化一个类型的使用
命名空间中。
只需将您的问题行更改为:
markupConverter =新MarkupConverter.MarkupConverter(); / *这里的解决方案!* /
......,你应该罚款。
Coders, I am trying to convert a XAML string to HTML using a library I found here , but I have a problem with creating a new instance of the object that would let me use the library. I already added a reference to the library in my Asp.net project and I would like to use it in a WCF file.
The problem is that whenever I try to instantiate a new object with the new keyword, I get an error that says:
'MarkupConverter' is a 'namespace' but is used like a 'type'.
Here is my code, notice that I am creating a new object just like the example shown in the library link above, please help:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Services;
using System.Net.Mail;
using System.ServiceModel.Activation;
using System.Data.SqlClient;
using MarkupConverter;
namespace AspPersonalWebsite
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 //: IService1
{
private string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
private IMarkupConverter markupConverter;
[OperationContract]
public string convertXAMLToHTML(string XAMLtext)
{
string htmlText = "";
markupConverter = new MarkupConverter(); /*PROBLEM IS HERE*/
htmlText = markupConverter.ConvertXamlToHtml(XAMLtext);
return htmlText;
}
}
}
Confusion is arising because the actual type is MarkupConverter.MarkupConverter
, the compiler seems to think your new MarkupConverter
is an attempt to use a namespace as a type, rather than an attempt to instantiate a type inside your using
namespace.
Simply change your problem line to:
markupConverter = new MarkupConverter.MarkupConverter(); /*SOLUTION HERE!*/
..and you should be fine.
这篇关于“像使用一种类型的命名空间”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!