none
Console Application doesn't compile with neither .NET 4.0 nor.NET 4.0 Client Profile RRS feed

  • Question

  • Hi all,

    I'm using Visual Studio 2012 (but the problem is reproducible also with 2010).

    Platform Target: ANY Cpu.

    I have a Console Application with this Program class (this is in C#):

        class Program
        {
            private static void Main(string[] args)
            {
                var factory = Oracle.DataAccess.Client.OracleClientFactory.Instance;
                var request = new System.Web.HttpRequest("", "", "");
            }
        }

    Referenced 2 assemblies: 

    • Oracle.DataAccess.dll (version 4.112.3.0) (x86 version) (you can use NuGet to have it faster)
    • System.Web.dll

    If I compile the solution with .NET 4.0 target framework, it says: The name 'Oracle' does not exist in the current context
    If I compile with .NET 4.0 Client Profile target framework , it says: The type or namespace name 'HttpRequest' does not exist in the namespace 'System.Web' (are you missing an assembly reference?).
    I know that Client Profile doesn't have System.Web, but I need to have both Oracle.DataAccess.dll and System.Web.dll !! 
    Is there a solution to this?


    • Edited by depp Friday, December 7, 2012 12:49 PM added NuGet suggestion
    Friday, December 7, 2012 12:45 PM

Answers

  • HI,

    in VS 2010 , i am successfully able to add reference to both System.Web and System.Drawing version 4.0 assemblies .

    Have you tried in VS 2010 .

    First remain in .NET 4.0 client frofile and add System.Drawing then switch your target to .NET 4.0 and then add reference to System.Web


    One good question is equivalent to ten best answers.

    • Marked as answer by depp Saturday, December 8, 2012 9:12 AM
    Friday, December 7, 2012 3:41 PM

All replies

  • Add the namespace at the top of the program with using statements

    using System.Web;    <--- this is a namespace

    Where there is duplication with the same class in two different libraries then you need to specify in the line of code which namespace to useso normally your would use this

    Normally you would just have to specify the following

    HttpRequest("", "", "");

    When a conflict exists then you need to include the full namespace of the class

    System.Web.HttpRequest("", "", "");


    jdweng

    Friday, December 7, 2012 2:16 PM
  • I have used the "using" directives, with this code: 

    using System.Web;
    using Oracle.DataAccess.Client;
    
    
    namespace TargetFrameworkError
    {
        class Program
        {
            private static void Main(string[] args)
            {
                var factory = OracleClientFactory.Instance;
                var request = new HttpRequest("", "", "");
            }
        }
    }

    But the result is the same (even if I try to use "usings" and set the full class names in the code).

    Here the Error List view after compiling

    With .NET 4.0: I've got 1 warning and 1 error.

    Warning The primary reference "Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86" could not be resolved because it has an indirect dependency on the framework assembly "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86" or retarget your application to a framework version which contains "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". TargetFrameworkError
    Error The type or namespace name 'Oracle' could not be found (are you missing a using directive or an assembly reference?)

    With .NET 4.0 Client Profile: I've got 3 warnings and an error.

    Warning The currently targeted framework ".NETFramework,Version=v4.0,Profile=Client" does not include the referenced assembly "System.Web". To fix this, either (1) change the targeted framework for this project or (2) remove the referenced assembly from the project.

    Warning The referenced component 'System.Web' could not be found.

    Warning There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

    Error The type or namespace name 'HttpRequest' could not be found (are you missing a using directive or an assembly reference?)


    These are the references (taken from csproj file of the project):

    <Reference Include="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
    <HintPath>..\packages\odp.net.x86.112.3.0\lib\net40\Oracle.DataAccess.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />


    • Edited by depp Friday, December 7, 2012 2:50 PM added references detail at the bottom of the reply
    Friday, December 7, 2012 2:44 PM
  • Hi,

    as your error shows , Oracle.DataAccess assembly needs System.Drawing assembly to be referenced in your project . Add that assembly in your project .

    Let me know about your issue .


    One good question is equivalent to ten best answers.

    Friday, December 7, 2012 2:57 PM
  • Hi bootstrap2,

    I've just tried. The errors are still there,

    but now if I target .NET 4.0 Client Profile I get: 

    Warning The currently targeted framework ".NETFramework,Version=v4.0,Profile=Client" does not include the referenced assembly "System.Web". To fix this, either (1) change the targeted framework for this project or (2) remove the referenced assembly from the project. TargetFrameworkError

    You can see the warning on System.Web:


    I can tell that if I target .NET 4.0, the warning is:

    Warning The primary reference "System.Drawing", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Drawing" or retarget your application to a framework version which contains "System.Drawing". TargetFrameworkError

    You can see the warning on System.Drawing:

    Friday, December 7, 2012 3:06 PM
  • Hi,

    What version of System.Drawing you have added in .NET 4.0 version of Console application ?


    One good question is equivalent to ten best answers.

    Friday, December 7, 2012 3:25 PM
  • System.Drawing is version 4.0.0.0 .

    System.Web is version 4.0.0.0 .

    The fact is that you can see System.Drawing assembly in the Reference Manager only if you target .NET 4.0 Client Profile. And you can see System.Web assembly in the Reference Manager only if you target .NET 4.0 full framework.

    Friday, December 7, 2012 3:30 PM
  • HI,

    in VS 2010 , i am successfully able to add reference to both System.Web and System.Drawing version 4.0 assemblies .

    Have you tried in VS 2010 .

    First remain in .NET 4.0 client frofile and add System.Drawing then switch your target to .NET 4.0 and then add reference to System.Web


    One good question is equivalent to ten best answers.

    • Marked as answer by depp Saturday, December 8, 2012 9:12 AM
    Friday, December 7, 2012 3:41 PM
  • Hi bootstrap2,

    I've just tried and it behaved as VS 2012.. Maybe the problem is that I installed VS2012 and it took .NET 4.5 on the machine?

    Friday, December 7, 2012 5:02 PM
  • Hi bootstrap2,

    I've just tried and it behaved as VS 2012.. Maybe the problem is that I installed VS2012 and it took .NET 4.5 on the machine?


    I don't think so , because even in VS 2012 , targeting .NET 4.5 version , i am able to reference both the assemblies .

    One good question is equivalent to ten best answers.

    Friday, December 7, 2012 6:24 PM
  • Hi bootstrap2, 

    Yes, of course. It works on my machine too, if I target .NET 4.5 framework.

    It's really strange. Today I tested these things on an other machine, and it worked. .NET 4.0 referencing Oracle.DataAccess. Worked fine.

    I tried to restart the other machine (the one with wich I wrote in this forum), and it worked fine again.

    Maybe there was something wrong in the environment. I suspended the OS every night for 4 days, without restarting it until today.

    Thank you

    Saturday, December 8, 2012 9:12 AM