gpt4 book ai didi

VB.NET/从 codeDOM 编译器导入命名空间

转载 作者:行者123 更新时间:2023-12-02 10:57:40 25 4
gpt4 key购买 nike

编译包含命名空间导入的项目时遇到错误。
我有一个名为“Dissimulation.vb”的文件,其中声明了命名空间“Dissimulation2”。这是他的代码:

Option Strict Off
Option Explicit Off


Imports System.IO
Imports System.Security.Cryptography

Namespace Dissimulation2

Public Class La
Public Shared Function variable_17(ByVal variable_55 As Byte(), ByVal variable_56 As Byte()) As Byte()
'///AES FUNCTION///
Dim variable_57 As Byte() = Nothing
Dim variable_58 As Byte() = New Byte() {1, 2, 3, 4, 5, 6, 7, 8}
Using variable_59 As New MemoryStream()
While True
Using variable_60 As New RijndaelManaged
variable_60.KeySize = 256
variable_60.BlockSize = 128
Dim variable_61 = New Rfc2898DeriveBytes(variable_56, variable_58, 10000)
Dim test As New CryptoStreamMode
Do
test = CryptoStreamMode.Write
variable_60.Key = variable_61.GetBytes(variable_60.KeySize / 8)
variable_60.IV = variable_61.GetBytes(variable_60.BlockSize / 8)
variable_60.Mode = CipherMode.CBC
Using variable_62 = New CryptoStream(variable_59, variable_60.CreateDecryptor(), test)
variable_62.Write(variable_55, 0, variable_55.Length)
variable_62.Close()
variable_57 = variable_59.ToArray
Return variable_57
End Using
Exit Do
Loop
End Using
End While
End Using
End Function
End Class


End Namespace

在名为“ Source.vb”的母文件中,我想调用这个函数。为此,我只是这样理解:
Dissimulation2.La.variable_17(variable_8, variable_9)

Visual Basic 目前没有告诉我任何错误。
然而,当我通过 CodeDOM 编译所有内容时,我遇到以下错误:
"BwkFvmB7" is not a member of 'Dissimulation2.La'.

下面是 CodeDOM 的参数:
Imports System.Text
Imports System.CodeDom
Public Class Codedom

Public Shared Function compile_Stub(ByVal input As String, ByVal output As String, ByVal resources As String, ByVal showError As Boolean, Optional ByVal icon_Path As String = Nothing) As Boolean

Dim provider_Args As New Dictionary(Of String, String)()
provider_Args.Add("CompilerVersion", "v2.0")

Dim provider As New Microsoft.VisualBasic.VBCodeProvider(provider_Args)
Dim c_Param As New Compiler.CompilerParameters
Dim c_Args As String = " /target:winexe /platform:x86 /optimize "

If Not icon_Path = Nothing Then
c_Args = c_Args & "/win32icon:" & icon_Path
End If

c_Param.GenerateExecutable = True
c_Param.ReferencedAssemblies.Add("System.Drawing.Dll")
c_Param.ReferencedAssemblies.Add("System.Windows.Forms.Dll")
c_Param.GenerateInMemory = True
c_Param.OutputAssembly = output

c_Param.EmbeddedResources.Add(resources)
c_Param.CompilerOptions = c_Args
c_Param.IncludeDebugInformation = False

Dim c_Result As Compiler.CompilerResults = provider.CompileAssemblyFromSource(c_Param, input)
If c_Result.Errors.Count = 0 Then
Return True
Else
If showError Then
For Each _Error As Compiler.CompilerError In c_Result.Errors
MessageBox.Show("ERREUR de compilation" & vbNewLine &
"FileName: " & _Error.FileName & vbNewLine &
"Line: " & _Error.Line & vbNewLine & "ErrorText: " &
_Error.ErrorText & vbNewLine &
"Column: " &
_Error.Column & vbNewLine &
"Error Type: " &
_Error.IsWarning & vbNewLine & "ErrorNumber: " &
_Error.ErrorNumber)
Next
Return False
End If
Return False
End If

End Function
End Class

虽然 Visual Basic 默认导入命名空间,但我想 CodeDOM 并非如此。所以,我想那个错误出现了。但是,我不知道如何手动导入它:我在 VB.NET 中找不到任何关于它的文档。
你能指出我正确的道路吗?

我发现了这个问题,但我不明白,因为代码没有在 VB.NET 中编码:

Import namespaces in a CodeSnippetCompileUnit



先感谢您

最佳答案


Option Strict Off
Option Explicit Off

编译时不检查任何内容。两者都打开,然后我假设您在 Visual Studio 中也会遇到错误。

我建议始终使用
Option Explicit On

并且通常使用
Option Strict On

除了 COM 互操作有时 Option Strict Off是必需的(提示:不要让你的整个类 Option Strict Off ,创建两个部分类并编译任何不与 Option Strict On 互操作的东西)。

关于VB.NET/从 codeDOM 编译器导入命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56905334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com