0

我在 WCF 应用程序中返回一个类文件。从 wsdl(WCF 应用程序)的 svcutil.exe 生成的类文件 AuthenticationService.cs 保存在 App_Code 中并在我的项目中使用。

public ActionResult ViewName()
    {
  AuthenicationServiceClient client = new AuthenicationServiceClient("BasicHttpBinding_IAuthenicationService");
  IList<CategoryInfo> category = new List<CategoryInfo>();
  category = client.GetCategories(0, true);
  return View(category);
}

CategoryInfo 类存在于 AuthenticationService.cs 中,我可以从控制器访问它,但不能在视图中使用它。当我在视图中使用相同的 CategoryInfo 时,它显示错误消息

In View
@model CategoryInfo

类 CategoryInfo

*错误:
“D:\ProjectName\Project Path\bin\ProjectName.dll”和 C:\Windows\Microsoft.NET\Framework\v4.0.30309\Temporary ASP.NET Files\root\1664c01d_shadow 中都存在“CategoryInfo”类型\b956618\414288438\30335072\App_Code.j4b-_1mm.dll*

有没有办法克服这个问题?

4

2 回答 2

3

从 wsdl(WCF 应用程序)的 svcutil.exe 生成的类文件 AuthenticationService.cs 被保存在 App_Code 中

那就是问题所在。App_CodeWeb 应用程序项目类型(这是 ASP.NET MVC 使用的)不应使用该文件夹。它适用于网站。因此,将这些类移到其他地方并删除App_Code不应出现在预编译的 Web 应用程序中的文件夹。请在此处阅读有关 Web 应用程序项目类型和网站之间的区别:http: //msdn.microsoft.com/en-us/library/dd547590 (v=vs.110).aspx

您的代码不起作用的原因是,当您预编译项目时(因为它是一种 Web 应用程序类型),CategoryInfo该类会进入生成的程序集。除了App_Code文件夹内所有内容的 ASP.NET 之外,在运行时会生成动态程序集并将它们放在输出中。所以基本上你最终会得到 2 个包含相同类的程序集。

于 2013-11-13T11:48:05.460 回答
0

Reply to my own question.

I was using the same CategoryInfo using the web service as well as in the project file as reference. My issue is resolved by removing the naming conflict by removing the referrence and fetching the CategoryInfo only from the Webservice client file.

Now i am not getting the error any more.

于 2013-12-18T13:13:21.750 回答