Invoke code not finding CodePagesEncodingProvider class of System.Text after migrating to 6.0

Hello,

Since we are starting the migration from .net4 to .net6, I have migrated the library we are using.
I was able to successfully fix all of the exceptions except one.

In my invoke code activity when I try to call System.Text.CodePagesEncodingProvider.Instance the compilation error occurs stating that the CodePagesEncodingProvider is not a member of System.Text

However from the Micosoft docs it seems that the version should be supported.

Moreover the intellisense does prompt it as a possible class of System.Text

I’ll try to fix it somehow but will be greatful for any ideas on how to tackle this.

1 Like

System.Text.Encoding

2 Likes

Hi,

For some reason, There is some case that System.Text.CodePagesEncodingProvider is not available in InvokeCode. So can you try to call it using InvokeMethod before the InvokeCode?
It will be also effective inside InvokeCode activity.

Regards,

2 Likes

You should be able to use System.Text.CodePagesEncodingProvider.Instance inside the Invoke Code as long as you use it before the Invoke Code first, e.g. in an Assign statement or as an In Argument.

For example:

image

or

Console output:

image

Code:

Console.WriteLine("Before: " + System.Text.Encoding.GetEncodings.Length.ToString)
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance)
Console.WriteLine("After: " + System.Text.Encoding.GetEncodings.Length.ToString)
3 Likes

Understood, thank you all.

So the thing is that in .Net 6.0 you need to initialize the CodePagesEncodingProvider instance with invoke method or with variable. Otherwise the dll will not be recognized at the runtime, huh?

Everything works fine now.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.