Simple Enterprise Library console application refuses to compile

浪尽此生 提交于 2020-01-03 21:01:30

问题


I just downloaded and installed Microsoft Enterprise Library 5.0. I fired up VS 2010 to play with EL 5 and created a very simple console application. However, it would not compile. I got the following error:

The type or namespace name 'Data' does not exist in the namespace 'Microsoft.Practices.EnterpriseLibrary' (are you missing an assembly reference?)

I added Microsoft.Practices.EnterpriseLibrary.Common, Microsoft.Practices.EnterpriseLibrary.Data, and Microsoft.Practices.Unity references to my project.

Here's the simple code that refuses to compile.

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.Unity;

namespace EntLib
{
    class Program
    {
        static void Main(string[] args)
        {
            IUnityContainer container = new UnityContainer();
            container.AddNewExtension<EnterpriseLibraryCoreExtension>();
            var defaultDatabase = container.Resolve<Database>();
        }
    }
}

The error above complains about line #2 :

using Microsoft.Practices.EnterpriseLibrary.Data;

Someone probably will point out to a stupid mistake by me, but at the moment I fail to see it.

I tried to remove and add again Microsoft.Practices.EnterpriseLibrary.Data to refences but it didn't help.


回答1:


I found my answer at this question. I changed target framework in my project to .NET Framework 4 from .NET Framework Client Profile.




回答2:


im suspecting that you are targeting a .NET client profile. When using the Microsoft.Practices.EnterpriseLibrary.Data assembly of EntLib 5.0, you are required to target the full .NET framework. Right click on your project, select Properties, and in the Applciation tab, select either .NET Framework 3.5 or .NET Framework 4.0 as value of the Target Framework property. This is a known issue in EntLib 5.0



来源:https://stackoverflow.com/questions/2751634/simple-enterprise-library-console-application-refuses-to-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!