Parser Errors with VS.NET

A

Adam Smith

Firstly I appologise for the cross post, I've discovered more information
which pinpoints VS.NET 2003 as the problem.

The issue: I'm trying to create a server control, after failure I'm trying
some simplistic controls to build from

I'm using the following code:

SimpleControl.cs
------------------
using System;
using System.Web.UI;

namespace MSPress.ServerControls
{
public class SimpleControl : Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.write("I don't do anything useful, ");
writer.write("but at least I'm a control...");
}
}
}
-----------------

SimpleControl.vb
-----------------
Imports System
Imports System.Web.UI

Namespace MSPress.ServerControls
Public Class SimpleControl : Inherits Control

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
writer.write("I don't do anything usefula, ")
writer.write("but at least I'm a control...")
End Sub
End Class
End Namespace
-----------------

Webform1.aspx
-----------------
<%@ Register TagPrefix="msp" Namespace="MSPress.ServerControls"
Assembly="simplecontrol" %>
<%@ Page Language="VB" %>
<html>
<body>
<br>
Here is the output from our first custom control.
<br>
<MSP:SIMPLECONTROL id="simple1" runat="server" />
<br>
</body>
</html>
----------------

Webform1.aspx and Simplecontrol.cs are straight out of an MS book on server
controls and components.
I created the SimpleControl.vb based on the cs file.

I have compiled and run these as seperate non-vs.net web applications and
both work fine.
When I run them through vs.net, the c# version works fine but the vb version
creates an error:

ERROR:
------------
Description: An error occured during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: Could not load type
MSPress.ServerControls.SimpleControl from assembly test2,
Version=1.0.1644.25788, Culture=neutral, PublicKeyToken=null

Source Error:

Line 9: <msp:SimpleControl id="simple1" runat="server" />
------------

Does anyone know why vs.net would run a c# server control correctly but not
a vb one, even when the code is workable.

Thanks in advance,
Adam Smith
 
J

John Saunders

Adam Smith said:
Firstly I appologise for the cross post, I've discovered more information
which pinpoints VS.NET 2003 as the problem.

The issue: I'm trying to create a server control, after failure I'm trying
some simplistic controls to build from

I'm using the following code:

SimpleControl.cs
------------------
using System;
using System.Web.UI;

namespace MSPress.ServerControls
{
public class SimpleControl : Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.write("I don't do anything useful, ");
writer.write("but at least I'm a control...");
}
}
}
-----------------

SimpleControl.vb
-----------------
Imports System
Imports System.Web.UI

Namespace MSPress.ServerControls
Public Class SimpleControl : Inherits Control

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
writer.write("I don't do anything usefula, ")
writer.write("but at least I'm a control...")
End Sub
End Class
End Namespace
-----------------

Webform1.aspx
-----------------
<%@ Register TagPrefix="msp" Namespace="MSPress.ServerControls"
Assembly="simplecontrol" %>
<%@ Page Language="VB" %>
<html>
<body>
<br>
Here is the output from our first custom control.
<br>
<MSP:SIMPLECONTROL id="simple1" runat="server" />
<br>
</body>
</html>
----------------

Webform1.aspx and Simplecontrol.cs are straight out of an MS book on server
controls and components.
I created the SimpleControl.vb based on the cs file.

I have compiled and run these as seperate non-vs.net web applications and
both work fine.
When I run them through vs.net, the c# version works fine but the vb version
creates an error:

ERROR:
------------
Description: An error occured during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: Could not load type
MSPress.ServerControls.SimpleControl from assembly test2,
Version=1.0.1644.25788, Culture=neutral, PublicKeyToken=null

Source Error:

Line 9: <msp:SimpleControl id="simple1" runat="server" />

"Could not load type" is a fairly broad error, as there can be many
different reasons why the type can't be loaded. It's possible the assembly
wasn't found, that the type wasn't in the assembly, or even that the
assembly was corrupted (I had this happen to me).

Now, I question right away that you have two controls with the same name.
Try renaming the VB control and using the new name in the Register
directive.
 
A

Adam Smith

I'm not using the two controls at the same time. I originally tried to code
a control in VB, and after having another example control fail I tried a C#
one. The C# example (below) worked. I then converted it into VB as a test,
which promptly errored with the "Could not load type" error.

As you can see, this is a massively infuriating problem centered entirely
around VB under VS.NET. It is specific to server controls or at least the
method in which they are called, since user controls work just dandy.
Both the C# and VB implimentations work as stand alone compiled
applications.

John Saunders said:
"Could not load type" is a fairly broad error, as there can be many
different reasons why the type can't be loaded. It's possible the assembly
wasn't found, that the type wasn't in the assembly, or even that the
assembly was corrupted (I had this happen to me).

Now, I question right away that you have two controls with the same name.
Try renaming the VB control and using the new name in the Register
directive.
 
J

John Saunders

Adam Smith said:
I'm not using the two controls at the same time. I originally tried to code
a control in VB, and after having another example control fail I tried a C#
one. The C# example (below) worked. I then converted it into VB as a test,
which promptly errored with the "Could not load type" error.

Try running ildasm (from the Framework SDK) against the assembly containing
the VB control. If it looks ok, try running it against the C# version and
comparing the two.
 
A

Adam Smith

Thank you John, a thousand thank you's, I didn't know there was a dasm
provided with the framework, you can bet I'm going to use it more often as
well as have a scout around in the SDK's for stuff.

Now the problem is solved, and I shall enlighten anyone thats having similar
problems.
It seems that VS.NET takes it upon its self to add a VB prefix to namespaces
created in VB, unlike C# stuff which it leaves well alone. I'm not sure if
this is documented somewhere or theres an option in vs.net to turn it off.

The code provided below shows the simple change:

SimpleControl.vb
-----------------
Imports System
Imports System.Web.UI

Namespace MSPress.ServerControls
Public Class SimpleControl : Inherits Control

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
writer.write("I don't do anything usefula, ")
writer.write("but at least I'm a control...")
End Sub
End Class
End Namespace
-----------------

Webform1.aspx
-----------------
<%@ Register TagPrefix="msp" Namespace="VB.MSPress.ServerControls"
Assembly="simplecontrol" %>
<%@ Page Language="VB" %>
<html>
<body>
<br>
Here is the output from our first custom control.
<br>
<MSP:SIMPLECONTROL id="simple1" runat="server" />
<br>
</body>
</html>
 
J

John Saunders

Adam Smith said:
Thank you John, a thousand thank you's, I didn't know there was a dasm
provided with the framework, you can bet I'm going to use it more often as
well as have a scout around in the SDK's for stuff.

Now the problem is solved, and I shall enlighten anyone thats having similar
problems.
It seems that VS.NET takes it upon its self to add a VB prefix to namespaces
created in VB, unlike C# stuff which it leaves well alone. I'm not sure if
this is documented somewhere or theres an option in vs.net to turn it off.

Adam,

Glad it's working.

I've never seen VB add a "VB" prefix to a namespace. You should check your
project properties in VS.NET to see if you have "VB" set as the root
namespace.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top