如何修复自动创建接口函数的错误列表中的警告?
How to fix warnings in the error list for auto-created interface functions?
我在互操作 dll 上使用了 ILSpy,这样我就可以将代码编译到我的 exe 中。但是对于该代码中的每个函数和 属性,IDE 和编译器警告我 "Function/Property 'xxx' doesn't return a value on all code paths." 它工作正常,在我的错误列表和编译器输出中出现所有这些警告真是烦人.我可以在那里放一个 "Return Nothing" 吗?还是我需要让它一个人呆着?这是它的样子:
Imports System
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Namespace QBXMLRP2Lib
<ComImport, TypeLibType(CShort(2)), Guid("45F5708E-3B43-4FA8-BE7E-A5F1849214CB"), ClassInterface(CShort(0))> _
Public Class RequestProcessor2Class
Implements RequestProcessor2
Implements IRequestProcessor3
Implements IRequestProcessor4
Public Function BeginSession(qbFileName As String, reqFileMode As QBFileMode) As String Implements IRequestProcessor3.BeginSession
End Function
Public Sub CloseConnection() Implements IRequestProcessor3.CloseConnection
End Sub
Public ReadOnly Property ConnectionType As QBXMLRPConnectionType Implements IRequestProcessor3.ConnectionType
Get
End Get
End Property
End Class
End Namespace
I used ILSpy on an interop dll so that I could just compile the code
into my exe.
这是将 "Embed Interop Types" 设置为 True 的目的。
添加 Dll 作为项目引用。在 Solution Explorer 中,单击显示所有文件按钮并展开 References 节点。 Select 有问题的 dll 并右键单击它 select 显示属性。将 "Embed Interop Types" 设置为 True。这将导致编译器将任何需要的库类型嵌入到您的程序中。
我建议在调试期间将此设置保留为 False,以便您可以访问引用的 dll 中的所有类型信息。如果它设置为 True,您只能访问您的代码在编译之前引用的类型信息,并且如果您想引用新的类型信息,使用“编辑并继续”会很痛苦。
我在互操作 dll 上使用了 ILSpy,这样我就可以将代码编译到我的 exe 中。但是对于该代码中的每个函数和 属性,IDE 和编译器警告我 "Function/Property 'xxx' doesn't return a value on all code paths." 它工作正常,在我的错误列表和编译器输出中出现所有这些警告真是烦人.我可以在那里放一个 "Return Nothing" 吗?还是我需要让它一个人呆着?这是它的样子:
Imports System
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices
Namespace QBXMLRP2Lib
<ComImport, TypeLibType(CShort(2)), Guid("45F5708E-3B43-4FA8-BE7E-A5F1849214CB"), ClassInterface(CShort(0))> _
Public Class RequestProcessor2Class
Implements RequestProcessor2
Implements IRequestProcessor3
Implements IRequestProcessor4
Public Function BeginSession(qbFileName As String, reqFileMode As QBFileMode) As String Implements IRequestProcessor3.BeginSession
End Function
Public Sub CloseConnection() Implements IRequestProcessor3.CloseConnection
End Sub
Public ReadOnly Property ConnectionType As QBXMLRPConnectionType Implements IRequestProcessor3.ConnectionType
Get
End Get
End Property
End Class
End Namespace
I used ILSpy on an interop dll so that I could just compile the code into my exe.
这是将 "Embed Interop Types" 设置为 True 的目的。
添加 Dll 作为项目引用。在 Solution Explorer 中,单击显示所有文件按钮并展开 References 节点。 Select 有问题的 dll 并右键单击它 select 显示属性。将 "Embed Interop Types" 设置为 True。这将导致编译器将任何需要的库类型嵌入到您的程序中。
我建议在调试期间将此设置保留为 False,以便您可以访问引用的 dll 中的所有类型信息。如果它设置为 True,您只能访问您的代码在编译之前引用的类型信息,并且如果您想引用新的类型信息,使用“编辑并继续”会很痛苦。