开发者

Extension and CodeDomProvider

I am having problems with CodeDomProvider. When I compile a code VB, there is not an error. But, if this code has extensions (ex: string().contains(), char().count, char().AsEnumerable, etc.) at the moment that I call these functions, it's returns an exception equal for all these extensions:

'Public Member 'Count' at type 'Char()' not found'

'Public Member 'Contains' at type 'String()' not found'


Dim refs() As String = {"mscorlib.dll", "System.dll", "Microsoft.VisualBasic.dll","system.xml.dll", "system.core.dll", "system.data.dll"}

oCParams.ReferencedAssemblies.AddRange(refs)

These are the Assembly that is referenced to the compile, and this is also configurated for run in Framework 4.0.


    Dim Param As New Dictionary(Of String, String)

    Param.Add(开发者_如何学Go"CompilerVersion", "v4.0")

    Dim oCodeProvider = CodeDomProvider.CreateProvider("VisualBasic", Param)

This code is inside a string:

Imports System
Imports System.Xml
Imports System.Data
Imports System.Collections
Imports System.Linq.Expressions
Imports System.Linq
Imports System.String
Imports System.Linq.Enumerable
Imports System.Collections.Generic
Imports System.Runtime.CompilerServices
Imports System.Runtime.CompilerServices.ExtensionAttribute

Namespace Teste
Class Classe
Public Shared Function ProcessarLink(ByVal URL As System.Uri) As Boolean
Dim QueryString = URL.Query.Remove(0, 1).Split("&"c).tolist

If QueryString.Contains("xxx") Then
...
End If

End Function 
Public Shared Function Personalizar(ByRef Vetor() As Char) As System.Collections.Generic.Dictionary(Of String,Object) 
...
Dim Total As Integer = Vetor.Count
...
End Function 
End Class 
End Namespace

After I use it for compile my Assembly.

The code compiles without errors, but when I call the function 'ProcessarLink', it returns me the exception in 'Contains', or when I call the function 'Personalizar' the errors appears with the 'Count'. This happens with the others extensions too, like AsEnumerable, etc.

What is the problem?


It sounds like your codefile needs to import the extension methods - i.e. it doesn't include:

Imports System.Linq

Have you done that? If not, can you post an example vb codefile where you are seeing the errors?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜