locked
compilation error - CS0122: 'mapdistance.DistHandler' is inaccessible due to its protection level (EDITED) RRS feed

  • Question

  • User379720387 posted

    I am querying the Bing Maps api through a rest service, based on information from a MSDN tutorial.

    Originally I started out with a test project in Visual Studio, and the code works there as designed.

    Now I have copied the 3 files involved to where it is going to live as part of my site, and I get the error message above.

    C:\Windows\system32> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\assembly\GAC_MSIL\System.Data.SqlServerCe\4.0.0.0__89845dcd8080cc91\System.Data.SqlServerCe.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\5e9a55a4\48f4a257_d715ce01\RestSharp.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\3ff72591\d8ce7474_b735cf01\zxing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Helpers\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.Helpers.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\32bcbe5a\68a37e57_d715ce01\Newtonsoft.Json.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\ec6e8f68\88e94967_d715ce01\iTextSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\8cf09cbd\58f686f8_d615ce01\DotNetOpenAuth.OAuth.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WebMatrix.WebData\v4.0_2.0.0.0__31bf3856ad364e35\WebMatrix.WebData.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\9ac13ad6\68708ef8_d615ce01\DotNetOpenAuth.AspNet.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\App_Code.5dgnjctq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\a8d694dd\08b946f8_d615ce01\DotNetOpenAuth.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\NuGet.Core\v4.0_1.6.30117.9648__31bf3856ad364e35\NuGet.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\846e796b\478fff65_726cce01\EntityFramework.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Administration\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Administration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\WebMatrix.Data\v4.0_2.0.0.0__31bf3856ad364e35\WebMatrix.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\0eae21ea\a2cb2997_a018cf01\Microsoft.Web.Helpers.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\f3f60bfd\50c835fc_66e2cf01\Twilio.WebMatrix.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.Entity.Design\v4.0_4.0.0.0__b77a5c561934e089\System.Data.Entity.Design.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.Razor.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http.WebRequest\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.WebRequest.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\1608e86e\58aa69f8_d615ce01\DotNetOpenAuth.OpenId.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Web.Infrastructure\v4.0_1.0.0.0__31bf3856ad364e35\Microsoft.Web.Infrastructure.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\11ca539d\a81379f8_d615ce01\DotNetOpenAuth.OpenId.RelyingParty.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\c7951ba8\0b447574_b735cf01\zxing.presentation.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\4daf8edb\69ddff65_726cce01\EntityFramework.SqlServer.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Web.PageInspector.Loader\v4.0_1.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Web.PageInspector.Loader.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\9de30ca2\e4929c02_d615ce01\Microsoft.Web.WebPages.OAuth.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\8b2c05e5\517e33fc_66e2cf01\Twilio.Api.dll" /R:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\assembly\dl3\3c4ebd20\c8788af8_d615ce01\DotNetOpenAuth.OAuth.Consumer.dll" /out:"C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\App_Web_testdistance.cshtml.cdcab7d2.s-jejj60.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701;612;618 /warnaserror-  "C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\App_Web_testdistance.cshtml.cdcab7d2.s-jejj60.0.cs" "C:\Users\robert\AppData\Local\Temp\Temporary ASP.NET Files\root\a4e278a5\19f17d51\App_Web_testdistance.cshtml.cdcab7d2.s-jejj60.1.cs"
    
    
    Microsoft (R) Visual C# Compiler version 4.0.30319.18408
    
    for Microsoft (R) .NET Framework 4.5
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    c:\Users\robert\Documents\My Web Sites\be\testdistance.cshtml(3,31): error CS0122: 'mapdistance.DistHandler' is inaccessible due to its protection level
    c:\Users\robert\Documents\My Web Sites\be\testdistance.cshtml(4,5): error CS0118: 'System.Web.WebPages.WebPageRenderingBase.Response' is a 'property' but is used like a 'type'
    c:\Users\robert\Documents\My Web Sites\be\testdistance.cshtml(4,34): error CS0122: 'mapdistance.DistHandler' is inaccessible due to its protection level
    c:\Users\robert\Documents\My Web Sites\be\testdistance.cshtml(5,14): error CS0122: 'mapdistance.DistHandler' is inaccessible due to its protection level

    Googling "Is inaccessessible due to its protection level" does not result in anything useful to me at least.

    I am wondering what scenario would cause file to work in one application but not in the other?

    testdistance is the razor C code that calls DistHandler class file

    mapdistance is the name space inside DistHandler

    @using mapdistance;
    @{
        string locationsRequest = DistHandler.CreateRequest("Pasedena, MD", "Sparks, MD", "&avoid=minimizeTolls");
        Response locationsResponse = DistHandler.MakeRequest(locationsRequest);
        var rt = DistHandler.ProcessResponse2(locationsResponse);
    
    
    }

    And DistHandler.cs, at least the first few lines:

    using System;
    using System.Net;
    using System.Runtime.Serialization.Json;
    using BingMapsRESTService.Common.JSON;
    
    
    namespace mapdistance
    {
        static class DistHandler
        {
            static string BingMapsKey = "blahblah";
    
            public static string CreateRequest(string queryString1, string queryString2, string options)
            {
                string UrlRequest = "http://dev.virtualearth.net/REST/v1/Routes/Driving" +
                 "?wp.0=" + queryString1 +
                 "&wp.1=" + queryString2 +
                 options +
                 "&output=json" +
                 " &key=" + BingMapsKey;
                return (UrlRequest);
            }
    
            public static Response MakeRequest(string requestUrl)
            {
                try
                {
                    HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        if (response.StatusCode != HttpStatusCode.OK)
                            throw new Exception(String.Format(
                            "Server error (HTTP {0}: {1}).",
                            response.StatusCode,
                            response.StatusDescription));
                        DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));
                        object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
                        Response jsonResponse = objResponse as Response;
                        return jsonResponse;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return null;
                }
            }
    
    
            static public Route ProcessResponse2(Response locationsResponse)
            {
                int locNum = locationsResponse.ResourceSets[0].Resources.Length;
    
                Route location = (Route)locationsResponse.ResourceSets[0].Resources[0];
                return location;
    
                //for (int i = 0; i < locNum; i++)
                //{
                //    Route location = (Route)locationsResponse.ResourceSets[0].Resources[i];
                //    var x = location.TravelDistance;
                //}
    
    
            }

    EDIT: I am adding the main program that calls DistHandler in the VS application (which works)

    using System;
    using System.Net;
    using System.Runtime.Serialization.Json;
    using BingMapsRESTService.Common.JSON;
    using mapdistance;
    
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    string locationsRequest = DistHandler.CreateRequest("Hunt Valley, MD", "Pasedena, MD", "&avoid=minimizeTolls");
                    Response locationsResponse = DistHandler.MakeRequest(locationsRequest);
                    var rt =DistHandler.ProcessResponse2(locationsResponse);
                    Console.WriteLine(rt.TravelDistance.ToString() + " " + rt.TravelDuration.ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
            }
        }

    Tuesday, November 11, 2014 11:40 AM

Answers

  • User895691971 posted

    You're right. This problem is because by default the accessibility to the classes in .NET are set to be private. This class that you're showing doesn't have anything set to it, so the default properties would be applied. 

    static class DistHandler

    If you can, you can edit it and make it public. Like this

    public static class DistHandler

    then you will be able to use it. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 12, 2014 10:24 AM

All replies

  • User895691971 posted

    You're right. This problem is because by default the accessibility to the classes in .NET are set to be private. This class that you're showing doesn't have anything set to it, so the default properties would be applied. 

    static class DistHandler

    If you can, you can edit it and make it public. Like this

    public static class DistHandler

    then you will be able to use it. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 12, 2014 10:24 AM
  • User379720387 posted

    Yes, that did it.

    Thank you very much!

    Wednesday, November 12, 2014 11:05 AM