BC30469: Reference to a non-shared member requires an object reference

Fabra 1 Reputation point
2022-04-04T17:35:12.147+00:00

Hi guys,

Since I've been using Visual Studio 2022, I've got this following error:

Server Error in '/' 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.

Line 337:
Line 338: Dim ArrByte As Byte() = Convert.FromBase64String(strDadosBase64)
Line 339: Dim stringRetorno = Encoding.UTF8.GetString(ArrByte)
Line 340:
Line 341: Return stringRetorno

Source File: C:\DCTFReceitaNetBXWS\App_Code\SolicitarArquivosWs.vb Line: 339

Here's my class:

Line 1: Imports System.IO
Line 2: Imports System.Xml
Line 3: Imports System.IO.StringWriter
Line 4: Imports System.Collections.Generic
Line 5: Imports Serpro.Supde.DCTF.Entidades
Line 6: Imports Serpro.Supde.DCTF.AcessarSQLADA.SQLAda
Line 7:
Line 8: Public Class SolicitarArquivosWs
Line 9: Inherits Page
Line 10: Public Function RegistrarPedido(ByVal Entrada As String) As SaidaEn
Line 11: Dim unused As New SaidaEn
Line 12: Dim objSaidaEn As New SaidaEn
Line 13: Dim xmlDoc As New XmlDocument
Line 14: Dim objRetornoMsgLog As New RetornoMsgLog
Line 15: Dim objValidarXml As New ValidarXml
Line 16: Dim atrIdPedido As String = String.Empty
Line 17: Dim atrNiUsuario As String = String.Empty
Line 18: Dim atrTipoNi As String = String.Empty
Line 19: Dim atrTipoCertificado As String = String.Empty
Line 20: Dim atrNumeroSerieCertificado As String = String.Empty
Line 21: Dim atrCpfRespCertificado As String = String.Empty
Line 22: Dim atrDaNascRespCert As String = String.Empty
Line 23: Dim qtdRegistros As Integer = 0
Line 24: objSaidaEn.codRetorno = 0
Line 25: Dim objSaiEN As SaidaEn = objValidarXml.validarArquivoXML(Entrada, "SchemaXml\SolicitarArquivos.xsd", "RegistrarPedido")
Line 26:
Line 27: ' se retorno = 0 - É erro
Line 28: If objSaiEN.codRetorno = 0 Then
Line 29: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", objSaiEN.Saida, "Erro", objSaiEN.Saida)
Line 30: Return objSaidaEn
Line 31: End If
Line 32:
Line 33: Try
Line 34: Dim ListaNo As XmlNodeList = Nothing
Line 35: xmlDoc.LoadXml(Entrada)
Line 36:
Line 37: ' Procura a tag pedido
Line 38: ListaNo = xmlDoc.GetElementsByTagName("pedido")
Line 39: Dim nodePedido As XmlNode = ListaNo(0)
Line 40: atrIdPedido = nodePedido.Attributes("id").Value
Line 41: Dim atrIdTipo As String = nodePedido.Attributes("idtipo").Value
Line 42:
Line 43: ' Procura a tag usario
Line 44: Dim ListaNoUsuario As XmlNodeList = Nothing
Line 45: ListaNoUsuario = xmlDoc.GetElementsByTagName("usuario")
Line 46: Dim nodeUsuario As XmlNode = ListaNoUsuario(0)
Line 47: atrNiUsuario = nodeUsuario.Attributes("ni").Value.Trim
Line 48: atrTipoNi = nodeUsuario.Attributes("tiponi").Value.Trim
Line 49: atrTipoCertificado = nodeUsuario.Attributes("tipocertificado").Value
Line 50: atrNumeroSerieCertificado = nodeUsuario.Attributes("numeroserie").Value
Line 51: atrCpfRespCertificado = nodeUsuario.Attributes("cpfresponsavel").Value
Line 52: atrDaNascRespCert = nodeUsuario.Attributes("nascimento").Value
Line 53: Dim arrNIUsuario() As String
Line 54: Dim i1 As Integer = 0
Line 55: Dim intNiOK As Integer = 0
Line 56: Dim RelacaoCNPJ As String = ConfigurationManager.AppSettings("RelacaoCNPJ")
Line 57: arrNIUsuario = Split(RelacaoCNPJ, ";")
Line 58:
Line 59: ' Validar CNPJ
Line 60: If Integer.Parse(atrNiUsuario.Length) < 14 Then
Line 61: atrNiUsuario = atrNiUsuario.PadLeft(14, "0")
Line 62: End If
Line 63: For i1 = 0 To arrNIUsuario.Length - 1
Line 64: If atrNiUsuario.Trim = arrNIUsuario(i1).Trim Then
Line 65: intNiOK = 1
Line 66: Exit For
Line 67: End If
Line 68: Next
Line 69:
Line 70: Dim strMsg As String
Line 71:
Line 72: If intNiOK = 0 Then
Line 73: strMsg = "O CNPJ que consta no pedido não está autorizado a executar a extração"
Line 74: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", strMsg, "Erro", "", "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 75: objSaidaEn.codRetorno = 0
Line 76: Return objSaidaEn
Line 77: End If
Line 78:
Line 79: Dim strcnpj As String = String.Empty
Line 80: Dim strAnoCalendario As String = String.Empty
Line 81: Dim strArquivoCnpjAc As String = String.Empty
Line 82: Dim arrCnpjAnoCalendario(100) As String
Line 83: Dim xmlListaNoPesquisa As XmlNodeList = nodePedido.SelectNodes("pesquisa")
Line 84: If xmlListaNoPesquisa.Count > 0 Then
Line 85: For Each NoPesquisa As XmlNode In xmlListaNoPesquisa
Line 86: Dim idPesquisa As String = NoPesquisa.Attributes("id").Value
Line 87: Dim xmlListaNoCampo As XmlNodeList = NoPesquisa.SelectNodes("campo")
Line 88: If idPesquisa = "cnpjanocalendario" Then
Line 89: If xmlListaNoCampo.Count > 0 Then
Line 90: 'stcnpj = xmlListaNoCampo.Item(0).Attributes("valor").Value
Line 91: 'strAnoCalendario = xmlListaNoCampo.Item(1).Attributes("valor").Value
Line 92: For Each nocampo As XmlNode In xmlListaNoCampo
Line 93: If nocampo.Attributes("id").Value = "cnpj" Then
Line 94: strcnpj = nocampo.Attributes("valor").Value
Line 95: End If
Line 96: If nocampo.Attributes("id").Value = "anocalendario" Then
Line 97: strAnoCalendario = nocampo.Attributes("valor").Value
Line 98: End If
Line 99: Next
Line 100: If strcnpj = "" Or IsNothing(strcnpj) Then
Line 101: strMsg = "Pedido = " & atrIdPedido & " - Atributo cnpj não encontrado ou valor não informado"
Line 102: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", strMsg, "Erro", strMsg, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 103: Return objSaidaEn
Line 104: End If
Line 105: If strAnoCalendario = "" Or IsNothing(strAnoCalendario) Then
Line 106: strMsg = "Pedido = " & atrIdPedido & " - Atributo anocalendario não encontrado ou valor não informado"
Line 107: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", strMsg, "Erro", strMsg, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 108: Return objSaidaEn
Line 109: End If
Line 110: arrCnpjAnoCalendario(0) = strcnpj.PadRight(14, "0") & strAnoCalendario.PadRight(4, "0")
Line 111: ReDim Preserve arrCnpjAnoCalendario(0)
Line 112: End If
Line 113: Else
Line 114: If idPesquisa = "arquivocnpjanocalendario" Then
Line 115: For Each nocampo As XmlNode In xmlListaNoCampo
Line 116: If nocampo.Attributes("id").Value = "arquivo" Then
Line 117: strArquivoCnpjAc = nocampo.Attributes("valor").Value
Line 118: End If
Line 119: Next
Line 120: If strArquivoCnpjAc = "" Or IsNothing(strArquivoCnpjAc) Then
Line 121: strMsg = "Pedido = " & atrIdPedido & " - Atributo arquivocnpjanocalendario não encontrado ou valor não informado."
Line 122: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", strMsg, "Erro", strMsg, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 123: Return objSaidaEn
Line 124: End If
Line 125: Dim retTxt As String
Line 126:
Line 127: retTxt = DesconverteBase64_TXT(strArquivoCnpjAc)
Line 128: arrCnpjAnoCalendario = LerTXT(retTxt.ToString)
Line 129:
Line 130: If arrCnpjAnoCalendario.Length > 100 Then
Line 131: strMsg = "Pedido = " & atrIdPedido & " - A quantidade de itens de CNPJ/Ano calendario está maior que 100."
Line 132: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", strMsg, "Erro", strMsg, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 133: Return objSaidaEn
Line 134: End If
Line 135: Else
Line 136: strMsg = "Conteúdo da tag pesquisa inválido - " & idPesquisa
Line 137: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", "", "Erro", strMsg, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 138: objSaidaEn.codRetorno = 0
Line 139: Return objSaidaEn
Line 140: End If
Line 141: End If
Line 142: Next
Line 143: End If
Line 144:
Line 145: qtdRegistros = arrCnpjAnoCalendario.Length
Line 146: Dim intTipo As Integer = 0
Line 147: Select Case atrTipoNi
Line 148: Case "cpf"
Line 149: intTipo = "2"
Line 150: Case "cnpj"
Line 151: intTipo = "1"
Line 152: End Select
Line 153:
Line 154: Dim dicRetorno As New Dictionary(Of String, String)
Line 155: Dim parmametroOFP As New Text.StringBuilder()
Line 156: Dim ind As Integer = 0
Line 157: ' Chama programa Natural
Line 158: '#TSE-NU-NI-SOLICITANTE (N14) /* 0001 - 0014
Line 159: '#TSE-IN-TP-SOLICITANTE (N01) /* 0015 - 0015
Line 160: '#TSE-IN-TP-CERTIFICADO (A02) /* 0016 - 0017
Line 161: '#TSE-NU-SERIE-CERTIFICADO (A40) /* 0018 - 0057
Line 162: '#TSE-NU-PEDIDO (N10) /* 0058 - 0072
Line 163: '#TSE-TX-TP-DOCUMENTO (A30) /* 0073 - 0102
Line 164: '#TSE-TQ-OCORRENCIA (N03) /* 0103 - 0105
Line 165: '#TSE-GR-PEDIDO (100) /* 0106 - 2005
Line 166: ' 04 #TSE-NU-NI-PEDIDO (N14)
Line 167: ' 04 #TSE-NU-PERIODO (N04)
Line 168: parmametroOFP.Append(atrNiUsuario.PadLeft(14, "0"))
Line 169: parmametroOFP.Append(intTipo)
Line 170: parmametroOFP.Append(atrTipoCertificado.PadRight(2, " "))
Line 171: parmametroOFP.Append(atrNumeroSerieCertificado.PadRight(40, " "))
Line 172: parmametroOFP.Append(atrIdPedido.PadLeft(10, "0"))
Line 173: parmametroOFP.Append(atrIdTipo.PadRight(30, " "))
Line 174: parmametroOFP.Append(qtdRegistros.ToString.PadLeft(3, "0"))
Line 175: For ind = 0 To arrCnpjAnoCalendario.Length - 1
Line 176: parmametroOFP.Append(arrCnpjAnoCalendario(ind).ToString)
Line 177: Next
Line 178:
Line 179: dicRetorno = RegistrarPedidoOFP(parmametroOFP.ToString)
Line 180:
Line 181: If dicRetorno("Codigo") = "01" Then
Line 182:
Line 183: ' Gera arquivo XML de Saida
Line 184: Dim objRetornoArquivos As New RetornoSolicitarArquivosEn.retornoarquivos
Line 185: ' Tag Pedido
Line 186: Dim objPedido As New RetornoSolicitarArquivosEn.retornoarquivosPedido
Line 187: objPedido.id = atrIdPedido
Line 188:
Line 189: Select Case atrTipoNi
Line 190: Case "cpf"
Line 191: objPedido.tiponidestinatario = RetornoSolicitarArquivosEn.tipoNIType.cpf
Line 192: objPedido.tiponidestinatarioSpecified = RetornoSolicitarArquivosEn.tipoNIType.cpf
Line 193: Case "cnpj"
Line 194: objPedido.tiponidestinatario = RetornoSolicitarArquivosEn.tipoNIType.cnpj
Line 195: objPedido.tiponidestinatarioSpecified = RetornoSolicitarArquivosEn.tipoNIType.cnpj
Line 196: Case Else
Line 197: objPedido.tiponidestinatario = RetornoSolicitarArquivosEn.tipoNIType.zero
Line 198: objPedido.tiponidestinatarioSpecified = RetornoSolicitarArquivosEn.tipoNIType.zero
Line 199: End Select
Line 200:
Line 201: objPedido.nidestinatario = atrNiUsuario
Line 202: objPedido.dataprevista = dicRetorno("daPrevistaAtend").Substring(0, 4) & "-" & dicRetorno("daPrevistaAtend").Substring(4, 2) & " -" & dicRetorno("daPrevistaAtend").Substring(6, 2)
Line 203: objPedido.situacao = RetornoSolicitarArquivosEn.situacaoType.processando
Line 204:
Line 205: ' mensagem e log
Line 206: Dim objMensagemusuario As New RetornoSolicitarArquivosEn.retornoarquivosMensagemusuario
Line 207: objMensagemusuario.nivelmsg = RetornoSolicitarArquivosEn.nivelMensagemType.info
Line 208: objMensagemusuario.Value = "Pedido(nº) " & atrIdPedido & ", Data prevista: " & dicRetorno("daPrevistaAtend").Substring(6, 2) & "/" & dicRetorno("daPrevistaAtend").Substring(4, 2) & "/" & dicRetorno("daPrevistaAtend").Substring(0, 4) & ", Situação: Processando"
Line 209: objRetornoArquivos.mensagemusuario = objMensagemusuario
Line 210: 'objRetornoArquivos.log = objMensagemusuario.Value
Line 211: objRetornoArquivos.pedido = objPedido
Line 212: objPedido = Nothing
Line 213: objMensagemusuario = Nothing
Line 214: Dim ns As New Serialization.XmlSerializerNamespaces()
Line 215: ns.Add("", "")
Line 216: Try
Line 217: Dim serializer As New Serialization.XmlSerializer(GetType(RetornoSolicitarArquivosEn.retornoarquivos), "")
Line 218:
Line 219: Using writer As System.IO.StringWriter = New Utf8StringWriter
Line 220: serializer.Serialize(writer, objRetornoArquivos, ns)
Line 221: objSaidaEn.Saida = writer.ToString.Remove(0, 40) ' remover o cabecalho do xml "<?xml version="1.0" encoding="utf-8"?>"
Line 222: End Using
Line 223:
Line 224: objRetornoArquivos = Nothing
Line 225:
Line 226: Catch ex As Exception
Line 227: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", ex.Message.ToString, "Erro", ex.Message.ToString, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 228: Return objSaidaEn
Line 229: End Try
Line 230:
Line 231: ' Validar xml gerado na saída
Line 232: objSaiEN = objValidarXml.validarArquivoXML(objSaidaEn.Saida, "SchemaXmlSaida\RetornoSolicitarArquivos.xsd", "RegistrarPedido")
Line 233:
Line 234: If objSaiEN.codRetorno = 0 Then
Line 235: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", objSaiEN.Saida, "Erro", objSaiEN.Saida, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 236: Return objSaidaEn
Line 237: End If
Line 238:
Line 239: objSaidaEn.codRetorno = 1
Line 240: Else
Line 241: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", dicRetorno("Mensagem").Trim, "Erro", dicRetorno("Mensagem").Trim, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 242: Return objSaidaEn
Line 243: End If
Line 244:
Line 245: Catch ex As Exception
Line 246: objSaidaEn.Saida = objRetornoMsgLog.RetornoMsgLog("retornoarquivos", ex.Message.ToString, "Erro", ex.Message.ToString, "SolicitarArquivosWs.vb", atrIdPedido, atrNiUsuario, atrTipoNi, atrTipoCertificado, atrNumeroSerieCertificado, atrCpfRespCertificado, atrDaNascRespCert)
Line 247: Finally
Line 248: objSaiEN = Nothing
Line 249: objValidarXml = Nothing
Line 250: xmlDoc = Nothing
Line 251: objRetornoMsgLog = Nothing
Line 252: End Try
Line 253:
Line 254: Return objSaidaEn
Line 255: End Function
Line 256: Private Function RegistrarPedidoOFP(ByVal parmametroOCP As String) As Dictionary(Of String, String)
Line 257:
Line 258: Dim objSqlada As ConSQLADA
Line 259: Dim RetDic As New Dictionary(Of String, String)
Line 260: Dim RetDicErro As New Dictionary(Of String, String)
Line 261: Dim comando As String
Line 262: Dim strRetorno As String = ""
Line 263: Dim cod_retorno As String = "00"
Line 264:
Line 265: Try
Line 266: objSqlada = New ConSQLADA()
Line 267: Catch ex As Exception
Line 268: RetDic.Add("Codigo", "99")
Line 269: RetDic.Add("Mensagem", "Erro na instanciando da classe SQLAda = " + ex.Message.ToString.Trim)
Line 270: Return RetDic
Line 271: End Try
Line 272:
Line 273: Try
Line 274: objSqlada.Conectar()
Line 275: comando = "SET CONVERT ON"
Line 276: objSqlada.ExecutaComando(comando)
Line 277: Catch ex As SQLAdaException
Line 278: objSqlada.Desconecta()
Line 279: RetDic.Add("Codigo", "99")
Line 280: RetDic.Add("Mensagem", "Conexão SQLADA falhou = " + ex.Mensagem.ToString.Trim)
Line 281: Return RetDic
Line 282: End Try
Line 283:
Line 284: Try
Line 285: comando = "SET PARAMETER ML=3000" ' tamanho do registro de entrada
Line 286: objSqlada.ExecutaComando(comando)
Line 287: Catch ex As Exception
Line 288: objSqlada.Desconecta()
Line 289: RetDic.Add("Codigo", "99")
Line 290: RetDic.Add("Mensagem", "Conexão SQLADA falhou = " + ex.Message.ToString.Trim)
Line 291: Return RetDic
Line 292: End Try
Line 293:
Line 294: Try
Line 295: comando = "EXEC O96026SN K34500 O34500FP" & parmametroOCP.ToString 'sincrono
Line 296:
Line 297: objSqlada.ExecutaComando(comando)
Line 298:
Line 299: If objSqlada.NumeroRegistros > 0 Then
Line 300: strRetorno = objSqlada.Dados()
Line 301: cod_retorno = strRetorno.Substring(0, 1)
Line 302: If cod_retorno = "1" Then
Line 303: '#TSS-COD-RET (N01)
Line 304: '#TSS-MSG-RET (A50)
Line 305: '#TSS-NU-NI-PEDIDO (N14)
Line 306: '#TSS-NU-PERIODO (N04)
Line 307: '#TSS-DA-PREVSITA-ATEND (N08)
Line 308: RetDic.Add("Codigo", "01")
Line 309: RetDic.Add("Mensagem", strRetorno.Substring(1, 50))
Line 310: RetDic.Add("nuNiPedido", strRetorno.Substring(51, 14))
Line 311: RetDic.Add("nuPeriodo", strRetorno.Substring(65, 4))
Line 312: RetDic.Add("daPrevistaAtend", strRetorno.Substring(69, 8))
Line 313: Else
Line 314: RetDic.Add("Codigo", "99")
Line 315: RetDic.Add("Mensagem", strRetorno.Substring(1, 50))
Line 316: End If
Line 317: Return RetDic
Line 318: Else
Line 319: RetDic.Add("Codigo", "99")
Line 320: RetDic.Add("Mensagem", "O34500FP Retorno SQLADA numero de registro maior que Zero = " + cod_retorno.ToString)
Line 321: End If
Line 322: Catch ex2 As SQLAdaException
Line 323: RetDic.Add("Codigo", "99")
Line 324: RetDic.Add("Mensagem", "O34500FP Falhou erro SQLADA codigo = " & ex2.Codigo & " Mensagem " & ex2.Mensagem.ToString.Trim)
Line 325: Return RetDic
Line 326: Catch ex As Exception
Line 327: RetDic.Add("Codigo", "99")
Line 328: RetDic.Add("Mensagem", "O34500FP Falhou erro SQLADA = " + ex.Message.ToString.Trim)
Line 329: Return RetDic
Line 330: Finally
Line 331: objSqlada.Desconecta()
Line 332: objSqlada = Nothing
Line 333: End Try
Line 334: Return RetDic
Line 335: End Function
Line 336: Private Function DesconverteBase64_TXT(ByVal strDadosBase64 As String) As String
Line 337:
Line 338: Dim ArrByte As Byte() = Convert.FromBase64String(strDadosBase64)
Line 339: Dim stringRetorno = Encoding.UTF8.GetString(ArrByte)
Line 340:
Line 341: Return stringRetorno
Line 342:
Line 343: End Function
Line 344: Private Function LerTXT(dados As String) As String()
Line 345: Dim stringToRead As New StringBuilder(dados)
Line 346: Dim arrayDados(100) As String
Line 347: Using leitor As New StringReader(stringToRead.ToString())
Line 348: Dim qtde As Integer = 0
Line 349: Do
Line 350: Dim linha As String = leitor.ReadLine()
Line 351:
Line 352: If IsNothing(linha) Or String.IsNullOrEmpty(linha) Or qtde > 100 Then
Line 353: qtde -= 1
Line 354: Exit Do
Line 355: End If
Line 356: arrayDados(qtde) = linha.PadRight(18, "0")
Line 357: qtde += 1
Line 358: Loop
Line 359: ReDim Preserve arrayDados(qtde)
Line 360: End Using
Line 361: Return arrayDados
Line 362: End Function
Line 363: End Class

Tks a ton!

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Michael Taylor 51,346 Reputation points
    2022-04-04T18:19:08.287+00:00

    The specific lines you posted seem fine. That is valid VB code. However the full class you posted is missing a lot of declarations so it is going to be very hard for us to diagnose exactly where things are going wrong for you. For example in your code you have RetornoSolicitarArquivosEn.situacaoType.processando. Given that RetornoSolicitarArquivosEn appears earlier in a new statement leads me to believe it is a namespace name and therefore situacaoType is a shared class but that would be inconsistent with the naming. Therefore it could also be a type but then the line New RetornoSolicitarArquivosEn.retornoarquivos is creating a nested type within the parent type. Without knowing what that code looks like it is hard to say.

    Given that you're getting a runtime error that means the code is compiling in VS and blowing up at runtime when dynamically compiling code. That would mean that the code you posted for us isn't inside a class file that is being compiled by the compiler so I'm curious where it is coming from. Normally runtime errors like what you're seeing only occurs inside .vbhtml files or perhaps in the App_Code folder if you're using that feature.

    But again I'm assuming that your code actually compiles meaning when you tell VS to Build Solution it returns back that everything built successfully. If it doesn't build successfully then everything else is a mute point. Note that press F5 to debug your code isn't sufficient as VS can be told to ignore build errors which means it may "debug" but not your current source code which really makes things confusing.


  2. Yijing Sun-MSFT 7,071 Reputation points
    2022-04-05T07:21:34.263+00:00

    Hi @Fabra ,
    The Encoding.UTF8 is static. According to your error message, you maybe need shared class.

    I think you could replace the 376 line to these codes.

    Shared enc8 As Encoding = Encoding.UTF8  
    
    Dim bytes As Byte() = New Byte(.......) {}  
    Dim stringRetorno As String = Nothing  
    stringRetorno = enc8.GetString(bytes)  
    

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Jose Zero 576 Reputation points
    2022-04-05T22:03:19.363+00:00

    @Fabra , perhaps I´m late here, but, you getting same issue twice, first at line 339 (on your first post) then on line 376.
    To seems you just missing to set the Type of variable, write it as
    Dim stringRetorno As String = Encoding.UTF8.GetString(ArrByte)

    In VB when, a type is not defined Object Type is assumed, check this link for code BC42020

    In addition to @cooldatx recomendation, a suggestion for DesconverteBase64_TXT function

    Private Function DesconverteBase64_TXT(ByVal strDadosBase64 As String) As String  
        Dim stringRetorno As String = Nothing  
        If Not String.IsNullOrEmpty(strDadosBase64) Then  
          Dim ArrByte As Byte() = Convert.FromBase64String(strDadosBase64)  
          Try  
            stringRetorno = Encoding.UTF8.GetString(ArrByte)  
          Catch ex As Exception  
            stringRetorno = "Fail"  
          End Try  
        End If  
        Return stringRetorno  
      End Function  
    

    By the way, I do not have such error alert in VS2019, don´t know if rule is disabled or even if does exist in 2019


  4. Jose Zero 576 Reputation points
    2022-04-06T22:25:00.817+00:00

    There is something weird here, it was not supposed to have an error at Encoding.UTF8.GetString().
    Here in VS2019 - VB - .Net 4.6.1, it works as expected.
    Give a try and call it explicitly like stringRetorno = System.Text.Encoding.UTF8.GetString(ArrByte)

    Or just create a new file, place DesconverteBase64_TXT function, and create a Sub just to call it, to see if it works
    The only thing came to my mind is an override of GetString method (if it is possible) somewhere else in your files or imported classes, like Serpro.Supde.DCTF.?????

    0 comments No comments