locked
The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias RRS feed

  • Question

  • User1045460610 posted

    Developed in Visual Studeio 2017 Enterprise, targeted to .net framework 4.6.1

    I have a web site that runs on my test server. When I copy it to a subfolder of a web portal on the development server I get these errors:

    1. Compiler Error Message: CS0103: The name 'DatabaseCheckIn' does not exist in the current context

    2. Warning: CS1685: The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'

    For the first error DatabaseCheckIn (See scripts listed below). The page runs in Visual Studio Browse on the Interne web browser and the IE Express web browser. So, I think the problem is with the second error.

    The second error looks like the web portal is using .net 4. 

    If I search for how to correct that error it looks like I should use -nostdlib

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/nostdlib-compiler-option

    But this page states that "The Do not reference mscorlib.dll build property doesn't exist in Visual Studio 2017."

    How can I get the page to run if it's referencing the wrong assembly?

    DatabaseCheckIn error

    It's declared in Database.cs

    using System;
    using System.Configuration;
    using System.Web.Configuration;

    //public class Database
    public class DatabaseCheckIn
    {
    static public String ConnectionString
    {
    get
    { // get connection string with name database from web.config.
    //return WebConfigurationManager.ConnectionStrings["ICS_NETConnectionString"].ConnectionString;
    return WebConfigurationManager.ConnectionStrings["OnGroundsWebSiteConnectionString"].ConnectionString;
    }
    }
    }

    aspx.cs

    using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.Services;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class updatecourses : System.Web.UI.Page
    {

    protected void Page_LoadComplete(object sender, EventArgs e)
    {

    //MessageBox.Show("You are in the Form.Shown event.");

    {
    SqlConnection con = new SqlConnection(DatabaseCheckIn.ConnectionString); <--Compiler Error Message: CS0103: The name 'DatabaseCheckIn' does not exist in the current context

    ...

    error listing

    Server Error in '/ICS' Application.


    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'DatabaseCheckIn' does not exist in the current context

    Source Error:


    Line 18: if (!Page.IsPostBack)
    Line 19: {
    Line 20: SqlConnection con = new SqlConnection(DatabaseCheckIn.ConnectionString);
    Line 21: {
    Line 22: //SqlDataAdapter da = new SqlDataAdapter("select * from courses order by RecordID", con);

    Source File: c:\Program Files\Jenzabar\ICS.NET\Portal\StaticPages\WebForm.CheckIn\listcoursestoday.aspx.cs    Line: 20


    Compiler Warning Messages:
    Warning: CS1685: The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'
    Source Error:


    [No relevant source lines]

    Warning: CS1685: The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'
    Source Error:


    [No relevant source lines]

    Show Detailed Compiler Output:

    c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" (excluded the rest it was very long)

    Microsoft (R) Visual C# Compiler version 4.7.3062.0

    for C# 5
    Copyright (C) Microsoft Corporation. All rights reserved.

    This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

    warning CS1685: The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'
    warning CS1685: The predefined type 'System.Threading.Tasks.Task' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll'
    c:\Program Files\Jenzabar\ICS.NET\Portal\StaticPages\WebForm.CheckIn\listcoursestoday.aspx.cs(20,51): error CS0103: The name 'DatabaseCheckIn' does not exist in the current context


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3429.0

    Wednesday, September 11, 2019 6:44 PM

Answers

  • User475983607 posted

    This is similar to your other post.  

    The System namespace usually targets the framework installed in the machine.   Simply you targeted a framework assembly that does not exist on the target machine.  I recommend building the project using the same framework installed in the target machine.  You can try copying the dll to your bin folder.  However, I'm not sure if this will work because your environment is not real clear.

    Another option is updating the framework on the target machine.

    1. Compiler Error Message: CS0103: The name 'DatabaseCheckIn' does not exist in the current context

    This is a basic error message alerting you that you are missing a reference and/or a using (C#) or Imports (VB).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 11, 2019 8:52 PM