'HtmlTextWriter' cannot be converted to 'HtmlTextWriter'.

B

Blaz Ziherl

Hi,

I am developing an application in VisualBasic .NET and got the
following error:

"An unhandled exception of type 'System.InvalidCastException' occurred
in microsoft.visualbasic.dll

Additional information: Argument 1 to method 'Control.RenderControl'
has type 'HtmlTextWriter' and cannot be converted to
'HtmlTextWriter'."

I am a newby to .NET, but this sounds a bit stupid to me. However, I
am also posting problematic part of the code where the error occurs:

Dim targetObj As New Object()
Dim sw As New StringWriter()
Dim tw As New System.Web.UI.HtmlTextWriter(sw)
targetObj = a.CreateInstance(aT.FullName)
targetObj.RenderControl(tw) <--- here's the problem!
MsgBox(sw.ToString())

Hopefuly someone will have an idea what's wrong.
Blaz Ziherl
(e-mail address removed)
 
E

Ed Kaim [MSFT]

Where are you initializing a and aT? If aT doesn't point to a valid type it
could be the problem.
 
B

Blaz Ziherl

Here's the declaration code for a and aT:

Dim a As [Assembly] =
[Assembly].LoadFrom("file://c:/windows/microsoft.net/framework/v1.1.4322/system.web.dll")

Dim aTypes As Type() = a.GetTypes()
Dim aT As Type
For Each aT In aTypes
...
Next

I hope you will see any possible problems here...if not, I can post
the whole code.

Blaz
 
J

Jon Skeet [C# MVP]

Blaz Ziherl said:
Here's the declaration code for a and aT:

Dim a As [Assembly] =
[Assembly].LoadFrom("file://c:/windows/microsoft.net/
framework/v1.1.4322/system.web.dll")

Dim aTypes As Type() = a.GetTypes()
Dim aT As Type
For Each aT In aTypes
...
Next

Ah - in that case the problem is that you've got two different
Assemblies loaded into your AppDomain - the one loaded automatically
and the one you specifically loaded. It's essentially the same problem
as the one explained here:

http://www.pobox.com/~skeet/csharp/plugin.html
 
B

Blaz Ziherl

Aha, now at least I know what's the problem. But I am not quite sure I
know how to solve it, LOL. Please note, that I am a .NET newby...so...

Thanks, Blaz

ps: I thought Microsoft came up with Visual Basic because they wanted
to create an easy to use development tool......it's becoming
everything but that, LOL! Visual Basic just ain't that basic anymore
;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top