none
Can anybody Let me know why compiler is considering this Class as non-CLS Compliant RRS feed

  • Question

  • Hi, i am using the below data structures all over my large project and i am getting like a zillion warning that these classes (and any forms using them) are not CLS-compliant. any ideas , why  and what should be done to make them CLS-compliant ???

    thank you in advance

        Public Class ObjDateFilter
            Public Enabled As Boolean = False
            Public FromDate As Integer, ToDate As Integer
            Sub New(Enabled_ As Boolean, FromDate_ As Integer, ToDate_ As Integer)
                Me.Enabled = Enabled_
                Me.FromDate = FromDate_
                Me.ToDate = ToDate_
            End Sub
            Sub New()
                'Normal Signature
            End Sub
        End Class
        Public Function GetDateFilterObj(ByVal Enabled_ As Boolean, ByVal FromDate_ As Integer, ByVal ToDate_ As Integer) As ObjDateFilter
            Dim result As New ObjDateFilter
            With result
                .Enabled = Enabled_
                .FromDate = FromDate_
                .ToDate = ToDate_
            End With
            Return result
        End Function
    
        Public Class ObjRangeFilter
            Public Enabled As Boolean = False
            Public FromValue As Decimal, ToValue As Decimal
            Sub New()
            End Sub
            Sub New(ByVal Enabled_ As Boolean, ByVal FromValue_ As Integer, ByVal toValue_ As Integer)
                Me.Enabled = Enabled_
                Me.FromValue = FromValue_
                Me.ToValue = toValue_
            End Sub
        End Class
        Public Function GetRangeObj(ByVal Enabled_ As Boolean, ByVal FromDate_ As Integer, ByVal ToDate_ As Integer) As ObjRangeFilter
            Dim result As New ObjRangeFilter
            With result
                .Enabled = Enabled_
                .FromValue = FromDate_
                .ToValue = ToDate_
            End With
            Return result
        End Function
    
        Public Class ObjCoinFilter
            Public Enabled As Boolean, Coin As Integer
        End Class
        Public Function GetCoinFilterObj(ByVal Enabled_ As Boolean, ByVal Coin_ As Integer) As ObjCoinFilter
            Dim Result As New ObjCoinFilter
            Result.Enabled = Enabled_ : Result.Coin = Coin_
            Return Result
        End Function
    
        Public Class ObjAddNewResult
            Public Success As Boolean = False, ErrorString As String = "", NewID As Integer, Exception_Obj As Exception
        End Class

    Friday, August 24, 2018 5:45 AM

All replies

  • Your data container classes should be using public properties.

    https://www.dotnetperls.com/property-vbnet

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/auto-implemented-properties

    Your data containers could be using  the DTO pattern.

    https://en.wikipedia.org/wiki/Data_transfer_object

    https://www.codeguru.com/vb/gen/vb_misc/oop/article.php/c7063/Data-Transfer-Object-Pattern-Goes-VBNET.htm

    Why?

    https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)

    <copied>

    Encapsulation is one of the fundamentals of OOP (object-oriented programming). It refers to the bundling of data with the methods that operate on that data. Encapsulation is used to hide the values or state of a structured data object inside a class, preventing unauthorized parties' direct access to them. Publicly accessible methods are generally provided in the class (so-called gettersand setters) to access the values, and other client classes call these methods to retrieve and modify the values within the object.

    <end>

    I am not going to repeat myself. You'll see the DTO pattern being used and explained in this thread. 

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/0facd464-ffa6-4b69-a926-b01826a0b7f4/vbnet-how-to-use-dynamic-link-libraries-?forum=vbgeneral

    Maybe, you'll pick-up on some of the other concepts I was trying to explain to the poster that unfortunately went right over his head.

    In particularly,  the Seperation of Concerns link in what is being explained, and the Seperation of Duty that is being explained in the Understanding Basics of  UI Design Patterns MVC MVP link. 

    By the way, the DTO(s) are kept in the a classlib project called Entities and all projects that needed to know about the DTO(s) have project refernce to Entities, the frontend and backend projects have reference to Entities. 

    Public Class DtoProject
    
        Public Property ProjectId As Int32
        Public Property ClientName As String
        Public Property ProjectName As String
        Public Property Technology As String
        Public Property ProjectType As String
        Public Property UserId As String
        Public Property StartDate  As DateTime
        Public Property EndDate As DateTime? 
        Public Property Cost As Decimal
       
    End Class

    Friday, August 24, 2018 7:42 AM
  • Hi,

    Try the following method:

    https://stackoverflow.com/questions/7065142/why-is-my-function-not-cls-compliant

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 24, 2018 8:03 AM
  •  Read through the CLSCompliantAttribute Class which is shown as the fix in the link that Alex has given you.

    If you say it can`t be done then i`ll try it

    Friday, August 24, 2018 8:25 PM
  •  Read through the CLSCompliantAttribute Class which is shown as the fix in the link that Alex has given you.

    If you say it can`t be done then i`ll try it

    IMHO, the OP has not architected the solution properly. I have seen or have written millions of lines of code in VB and C# .NET,  and I have never, ever, never,  ever, and never ever seen that warning message before until the poster posted about it. :)

    I am doing something similar in a ASP.NET MVC solution using a Basecontroller that all controllers use in global exception handling as an example and I am not getting such a warning message.

    I think it comes down to if the OP knew how to use Layered or N-Tier style along with MVP for his large project, then the OP wouldn't see the warning message,  and he would have a solid .NET solution. The code the OP has posted is not optimal programming for something that is basically a data container.

    I can only imagine what the rest of the code looks like, But it is good that the OP is using Object Oriented Programming to some degree.

    https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658117(v=pandp.10)

    https://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP

     
    Imports System.Web.Mvc
    Imports log4net
    
    Namespace Controllers
        Public MustInherit Class BaseController
            Inherits Controller
    
            private ReadOnly _logger As ILog
    
            public sub New()
                _logger = LogManager.GetLogger(GetType(BaseController))
            End sub
    
            Protected Overrides Sub OnException(filterContext As ExceptionContext)
                MyBase.OnException(filterContext)
    
                dim appexception as AppException = New AppException(CStr(filterContext.Exception.ToString()), _logger) 
    
                Server.ClearError()
    
                RedirectToControllers("Home", "TheError")
    
            End Sub
    
            private sub RedirectToControllers(control As string, action As string)
    
                dim routeData = new RouteData()
    
                routeData.Values("controller") = control
                routeData.Values("action") = action
    
                Dim controller As IController = new HomeController(nothing) 
                controller.Execute(New RequestContext(new HttpContextWrapper(system.Web.HttpContext.Current), routeData))
    
            End sub
            
        End Class
    End Namespace
    
    ==============================================
    
    Imports log4net
    
    Public Class AppException
        Inherits Exception
    
        private ReadOnly _logger As ILog
    
        Public Sub New(ByVal logger As ILog)
    
            _logger = logger
            LogError("An unexpected error occurred.", _logger)
    
        End Sub
    
        public sub New (byval message as String, logger As ILog) 
    
            _logger = logger
    
            LogError(message, _logger)
    
        End sub
    
        Public Sub New( ByVal message As String, ByVal innerException As Exception, ByVal logger As ILog)
    
            _logger = logger
            LogError(message, _logger)
    
            If Not (innerException Is Nothing) Then
                LogError(innerException.Message.ToString, _logger)
            End If
    
        End Sub
          
        Public Shared Sub LogError(ByVal message As String, ByVal logger As ILog)
            logger.Error(message)
        End Sub
    
      End Class
    =============================================
    Namespace Controllers
        Public Class ProjectController
            Inherits BaseController
    
            private readonly _projectModel As IProjectModel 
            private readonly _modelHelper As IModelHelper 
    
            public sub New (projectModel As IProjectModel, modelHelper As IModelHelper)
                _projectModel = projectModel
                _modelHelper = modelHelper
            End sub
    
            ' GET: Project
            <Authorize>
            public Function Index() As ActionResult
                Return View(_projectModel.GetProjectsByUserId(User.Identity.Name))
            End Function
    
            <Authorize>
            public Function  Details(Optional id As Int32 = 0) As ActionResult
                return  IIf(id = 0, nothing, View(_projectModel.Edit(id)))
            End Function
           
            <Authorize>
            public Function  Edit(Optional id As Int32 = 0) As ActionResult 
                return  IIf(id = 0, nothing, View(_projectModel.Edit(id)))
            End Function
    
            <Authorize>
            public Function  Create() as ActionResult
                return View(_projectModel.Create())
            End Function
            
            <Authorize>
            <HttpPost>
            public  Function Create(project as ProjectViewModels.Project, submit As string ) As ActionResult
    
                if submit = "Cancel" Then
                    return RedirectToAction("Index")
                End If
    
                Call ValidateddlProjectTypes()
    
                project.ProjectType = Request.Form("ddlProjectTypes")
    
                If ModelState.IsValid And _modelHelper.IsEndDateLessThanStartDate(project, "Project") Then
                    ModelState.AddModelError(String.Empty, "End Date cannot be less than Start Date.")
                End If
    
                if Not ModelState.IsValid Then
                    return View(_projectModel.PopulateSelectedList(project))
                End If
    
                _projectModel.Create(project, User.Identity.Name)
                return RedirectToAction("Index")
    
            End Function
         
            <Authorize>
            <HttpPost>
            public Function  Edit(project as ProjectViewModels.Project, submit As string ) As ActionResult
    
                if submit = "Cancel" Then
                    return RedirectToAction("Index")
                End If
    
                If ModelState.IsValid And _modelHelper.IsEndDateLessThanStartDate(project, "Project") Then
                    ModelState.AddModelError(String.Empty, "End Date cannot be less than Start Date.")
                End If
    
                if Not ModelState.IsValid Then
                    return View(_projectModel.PopulateSelectedList(project))
                End If
    
                dim theproject = project
    
                theproject.ProjectType = Request.Form("ProjectType")
    
                _projectModel.Edit(theproject, User.Identity.Name)
    
                return RedirectToAction("Index")
    
            End Function
    
            public  Function Delete(Optional id As Int32 = 0) as ActionResult
    
                if id > 0 Then
                   _projectModel.Delete(id)
                end If
    
                return RedirectToAction("Index")
    
            End Function
            
            public Function  Cancel() As ActionResult
                return RedirectToAction("Index", "Home")
            End Function
            
            public function UploadFile(id As Int32) As ActionResult
                return RedirectToAction("UploadFile", "Upload", new With { .id = id, .type = "PM" })
            End function
           
            private sub ValidateddlProjectTypes()
    
                if Request.Form("ddlProjectTypes") = String.Empty Then
                    exit sub
                End If
    
                for each  key1 in ModelState.Keys.ToList().Where(Function(key) ModelState.ContainsKey(key))
    
                    if key1 <> "ProjectType" Then
                        continue for
                    End If
    
                    ModelState(key1).Errors.Clear()
                next
    
            End sub
        End Class
    End Namespace
    
    

     
    Friday, August 24, 2018 11:21 PM
  •    and I have never, ever, never,  ever, and never ever seen that warning message before until the poster posted about it. :)


     
     That makes at least two of us,  I can't say I can ever remember seeing it either.  You could very well be right though,  I did not really look at the code much and can't say what the problem is.  I just read through the thread quickly and figured I would add a link to the MS documents for that attribute class,  just to be a nice guy I guess.    8)

    If you say it can`t be done then i`ll try it

    Saturday, August 25, 2018 12:20 AM
  •    and I have never, ever, never,  ever, and never ever seen that warning message before until the poster posted about it. :)


     

     That makes at least two of us,  I can't say I can ever remember seeing it either.  You could very well be right though, 

    LOL, I have seen that error!  

    I was getting it when I started with classes. I was trying to pass in the initial values in the new contructor and then copy to the class values. just like shown more or less and it did not like the way I named them with the underscores... and /or trying to do it that way or backwards upsidedown via the new constructor and then value = _value ... I dont recall exactly and was never sure what was wrong.


    Saturday, August 25, 2018 2:22 AM
  •    and I have never, ever, never,  ever, and never ever seen that warning message before until the poster posted about it. :)


     

     That makes at least two of us,  I can't say I can ever remember seeing it either.  You could very well be right though, 

    LOL, I have seen that error!  

    I was getting it when I started with classes. I was trying to pass in the initial values in the new contructor and then copy to the class values. just like shown more or less and it did not like the way I named them with the underscores... and /or trying to do it that way or backwards upsidedown via the new constructor and then value = _value ... I dont recall exactly and was never sure what was wrong.


    If you look at the code I have posted previously and this code, then you  see Dependency Injection using constructor injection using Unity IoC, and I am not getting that warning message, which the OP could implement in his Widows form project using Model View Presenter and Interfaces.

    After all, the whole purpose of an Interface is to expose public properties and/or methods implemented by the called class/object exposing them to the class/object that is calling the called class/object, the contract. 

    Imports System.Data.Entity
    Imports Microsoft.AspNet.Identity
    Imports Microsoft.AspNet.Identity.EntityFramework
    Imports ProgMgmntVB.Controllers
    Imports ProgMgmntVB.Models
    Imports ProgMgmntVB.WebApi
    Imports Unity
    Imports Unity.Injection
    Imports Unity.Lifetime
    Imports Unity.Mvc5
    
    Module ModuleUnity
    
        public class UnityConfig
    
            public shared sub RegisterComponents()
    
                dim container = new UnityContainer()
    
                container.RegisterType(Of IProjectModel, ProjectModel)() 
                container.RegisterType(Of ITaskModel, TaskModel)()
                container.RegisterType(Of IWebApi, WebApi.WebApi)()
                container.RegisterType(Of IModelHelper, ModelHelper)()
    
                'Identity 
    
                container.RegisterType(Of DbContext, ApplicationDbContext)(new HierarchicalLifetimeManager())
                container.RegisterType(of UserManager(of ApplicationUser))(new HierarchicalLifetimeManager())
                container.RegisterType(of IUserStore(of ApplicationUser), UserStore(of ApplicationUser))(New HierarchicalLifetimeManager())
                container.RegisterType(of AccountController)(new InjectionConstructor())
    
                DependencyResolver.SetResolver(new UnityDependencyResolver(container))
    
            End sub
        
        End Class
    End Module

    Imports ProgMgmntVB.WebApi
    Imports Entities
    Namespace Models
        Public Class ProjectModel
            Implements IProjectModel
    
            Private ReadOnly _webapi As IWebApi
    
            public sub New (webapi As IWebApi)
                _webapi = webapi
            End sub
    
            public Function  GetProjectsByUserId(userid As String) As ProjectViewModels Implements  IProjectModel.GetProjectsByUserId
    
                dim vm = new ProjectViewModels With {.Projects = new List(of ProjectViewModels.Project)}
    
                dim dtos = _webApi.GetProjsByUserIdApi(userid).ToList()
    
                vm.Projects.AddRange(dtos.Select(Function(dto) New ProjectViewModels.Project() With{.ProjectId = dto.ProjectId,
                                                                                                    .ClientName = dto.ClientName,
                                                                                                    .ProjectName = dto.ProjectName,
                                                                                                    .Technology = dto.Technology,
                                                                                                    .ProjectType = dto.ProjectType,
                                                                                                    .StartDate = dto.StartDate,
                                                                                                    .EndDate = dto.EndDate,
                                                                                                    .Cost = dto.Cost}).ToList())
                Return vm
    
            End Function
    
            public Function GetProjectById(id As Int32) As ProjectViewModels.Project Implements IProjectModel.GetProjectById
    
            dim responseDto = _webApi.GetProjByIdApi(id)
            dim project = New ProjectViewModels.Project With {.ProjectId = responseDto.ProjectId,
                                                                .ClientName = responseDto.ClientName,
                                                                .ProjectName = responseDto.ProjectName,
                                                                .Technology = responseDto.Technology,
                                                                .ProjectType = responseDto.ProjectType,
                                                                .StartDate = responseDto.StartDate,
                                                                .EndDate = responseDto.EndDate,
                                                                .Cost = responseDto.Cost}
            Return project
            End Function
    
            public function Create() As ProjectViewModels.Project Implements IProjectModel.Create
    
                Dim project = new ProjectViewModels.Project 
                return PopulateSelectedList(project)
    
            End function
           
            public sub Create(project As ProjectViewModels.Project, userid As string) Implements IProjectModel.Create
    
                dim dto = New DtoProject With{.ProjectId = project.ProjectId,
                                            .ClientName = project.ClientName,
                                            .ProjectName = project.ProjectName,
                                            .ProjectType = project.ProjectType,  
                                            .Technology = project.Technology,
                                            .UserId = userid,
                                            .StartDate = project.StartDate,
                                            .EndDate = project.EndDate,
                                            .Cost = project.Cost}
    
                _webApi.CreateProjectApi(dto)
            End sub
    
            public Function  Edit(id As int32)As ProjectViewModels.Project Implements IProjectModel.Edit
    
                dim responseDto = _webApi.GetProjByIdApi(id)
    
                dim project = New ProjectViewModels.Project with {.ProjectId = responseDto.ProjectId,
                                                                  .ClientName = responseDto.ClientName,
                                                                  .ProjectName = responseDto.ProjectName,
                                                                  .Technology = responseDto.Technology,
                                                                  .ProjectType = responseDto.ProjectType,
                                                                  .StartDate = responseDto.StartDate,
                                                                  .EndDate = responseDto.EndDate,
                                                                  .Cost = responseDto.Cost}
                project = PopulateSelectedList(project)
    
                Return project
            End Function
    
            public Sub Edit(project As ProjectViewModels.Project, userid as string) Implements IProjectModel.Edit
    
                dim dto = New DtoProject With {.ProjectId = project.ProjectId,
                                               .ClientName = project.ClientName,
                                               .ProjectName = project.ProjectName,
                                               .ProjectType = project.ProjectType,
                                               .Technology = project.Technology,
                                               .UserId = userid,
                                               .StartDate = project.StartDate,
                                               .EndDate = project.EndDate,
                                               .Cost = project.Cost}
                _webApi.UpdateProjectApi(dto)
            end Sub
            
            public sub Delete(id As int32) Implements IProjectModel.Delete
    
                _webApi.DeleteProjectApi(new DtoId With {.Id = id})
    
            End sub
            
            public Function  PopulateSelectedList(project As ProjectViewModels.Project ) As ProjectViewModels.Project Implements IProjectModel.PopulateSelectedList
    
                  dim dtocache as DtoCache = HttpContext.Current.Cache.Get("DtoCache") 
    
                  if IsNothing(dtocache) Then
                      dtocache = _webapi.GetCacheApi()
                      HttpContext.Current.Cache.Insert("DtoCache", dtocache, nothing,  _ 
                                                       DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration)
                  End If
    
                  project.ProjectTypes = new List(Of SelectListItem)
    
                  for each pt as DtoProjectType in dtocache.ProjectTypes
                      Dim sli = new SelectListItem With {.Value = pt.Value, .Text = pt.Text}
                      project.ProjectTypes.Add(sli)
                  Next
    
                  dim selected = (from a in project.ProjectTypes.Where(Function (a) a.Value = _ 
                                                       project.ProjectType) select a).SingleOrDefault()
    
                  if Not IsNothing(selected) then
                      selected.Selected = true
                  End If
    
                  return project
    
              End Function
    
        End Class
    End NameSpace
    
    =====================================================
    
    Imports System.Net
    Imports System.Net.Http
    Imports System.Net.Http.Headers
    Imports Entities
    Imports Newtonsoft.Json
    Imports Newtonsoft.Json.Linq
    
    Namespace WebApi
        Public Class WebApi
            Implements IWebApi
    
            #Region "Project"
            public Function  GetProjsByUserIdApi(userid As String) as List(of DtoProject) Implements IWebApi.GetProjsByUserIdApi
    
                dim dtoprojects = new List(Of DtoProject)
    
                dim url = "http://localhost/WebApiVB/api/project/GetProjectsByUserId?userid=" & userid
    
                Using webclient As New WebClient
                    dim json  = webclient.DownloadString(url)
                    Dim projects = JsonConvert.DeserializeObject(of List(Of DtoProject))(json)
                    dtoprojects = projects
                End Using
    
                Return dtoprojects
    
            End Function
           
            public Function GetProjByIdApi(id As int32) as DtoProject Implements IWebApi.GetProjByIdApi
    
                dim dto as DtoProject
    
                dim url = "http://localhost/WebApiVB/api/project/GetProjectById?id=" & id
    
                Using webclient As New WebClient
                    dim json  = webclient.DownloadString(url)
                    Dim project = JsonConvert.DeserializeObject(of DtoProject)(json)
                    dto = project
                End Using
               
                Return dto
    
            End Function
    
            public sub CreateProjectApi(dto As DtoProject) Implements IWebApi.CreateProjectApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/project/CreateProject"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
                
            End sub
            
            public sub UpdateProjectApi(dto As DtoProject) Implements IWebApi.UpdateProjectApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/project/UpdateProject"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
    
            End sub
    
            public sub DeleteProjectApi(dto As DtoId) Implements IWebApi.DeleteProjectApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/project/DeleteProject"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
    
            End sub
            #End Region
    
            #Region "Task"
    
            public function GetTasksByProjIdApi(id as int32) as List(Of DtoTask) Implements IWebApi.GetTasksByProjIdApi
    
                Dim dtotasks = new List(Of DtoTask)
    
                dim url = "http://localhost/WebApiVB/api/task/GetTasksByProjectId?id=" & id
    
                Using webclient As New WebClient
                    dim json  = webclient.DownloadString(url)
                    Dim tasks = JsonConvert.DeserializeObject(of List(Of DtoTask))(json)
                    dtotasks = tasks
                End Using
    
                Return dtotasks
    
            End function
            
            public Function  GetTaskByIdApi(id As int32) As DtoTask Implements IWebApi.GetTaskByIdApi
    
                dim dto as DtoTask
    
                dim url = "http://localhost/WebApiVB/api/task/GetTaskById?id=" & id
    
                Using webclient As New WebClient
                    dim json  = webclient.DownloadString(url)
                    Dim task = JsonConvert.DeserializeObject(of DtoTask)(json)
                    dto = task
                End Using
    
                return dto
    
            End Function
    
            public sub CreateTaskApi(dto As DtoTask) Implements IWebApi.CreateTaskApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/task/CreateTask"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
              
            End sub
            
            public sub UpdateTaskApi(dto As DtoTask) Implements IWebApi.UpdateTaskApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/task/UpdateTask"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
                
            End sub
            
            public sub DeleteTaskApi(dto As DtoId) Implements IWebApi.DeleteTaskApi
    
                Dim reqString As byte()
    
                Using webclient As New WebClient
    
                    dim url as string = "http://localhost/WebApiVB/api/task/DeleteTask"
                    webClient.Headers("content-type") = "application/json"
                    reqString = Encoding.Default.GetBytes(JsonConvert.SerializeObject(dto, Formatting.Indented))
                    webClient.UploadData(url, "post", reqString)
    
                End Using
    
            End sub
            #End Region  
            
            #Region "Cache"
    
            public Function  GetCacheApi() As DtoCache Implements IWebApi.GetCacheApi
    
                dim dtocache = new DtoCache()
    
                dim url = "http://localhost/WebApiVB/api/cache/GetCache"
    
                Using webclient As New WebClient
                    dim json  = webclient.DownloadString(url)
                    Dim deserialized = JsonConvert.DeserializeObject(of DtoCacheRoot)(json)
    
                    dtocache.ProjectTypes = deserialized.DtoCache.ProjectTypes
                    dtocache.Durations = deserialized.DtoCache.Durations
                    dtocache.Statuses = deserialized.DtoCache.Statuses
                    dtocache.Resources = deserialized.DtoCache.Resources
    
                End Using
    
                return dtocache
    
            End Function
            #End Region
    
        End Class
    End Namespace


    • Edited by DA924x Saturday, August 25, 2018 3:59 AM correction
    Saturday, August 25, 2018 3:56 AM