Problem with casting

  • Thread starter Thread starter Edgar Zavala
  • Start date Start date
E

Edgar Zavala

Hi,

We have an very strange error and i though you can help us to
understand what is happening.

First we have an interface defined as:

---code-begins
Public Interface ILessonReadersDAO
<... properties and methods here ...>
End Interface
---code-ends

Then we have different objects who implement that interface, and some
classes who use that interfaces... particulary we have one method in
one class defined as:

---code-begins
Public Shared Function GenerateContentTemplate(ByVal lessionId As
Long, ByVal sectionId As Long, ByVal slideId As Long, ByVal access As
ILessonReadersDAO) As StringTemplate
---code-ends

Now... the problem is with this code:

---code-begins
Dim access As ILessonReadersDAO = new LessonReadersADO()

Dim sTemplate As StringTemplate =
LessonContentBuilder.GenerateContentTemplate(LessonId, SectionId,
SlideId, access)
---code-ends

This code compiles ok but from time to time we get the following
message:
Option Strict On disallows implicit conversions from
'Lesson.ILessonReadersDAO' to 'Lesson.ILessonReadersDAO'.

If we recompile it works, just happens from time to time.

The VS IDE give us a hint to change 'access' to CType(access,
ILessonReadersDAO), we changed it:

---code-begins
Dim sTemplate As StringTemplate =
LessonContentBuilder.GenerateContentTemplate(LessonId, SectionId,
SlideId, access)
---code-ends

and we still have the same problem.

I don't know if somebody has the same problem or knows what is
happening here.

We use .Net 2.0, VS 2005, the solution has C# and VB.Net projecs.

Regards,
Edgar Zavala.
 
This message suggests to me that sometimes you are making a change that requires
rebuilding the project. It is as if the compiler sees the pending new version of
ILessonReadersDAO as a different type from the last built version of
ILessonReadersDAO.

If rebuilding fixes it every time, I would not worry about it. It happens..

Yes we can live with that, but is anoying and time consuming because
requires a Rebuild, also ... the porblem seems to be the casting
"Option Strict On disallows implicit conversions from
'Lesson.ILessonReadersDAO' to 'Lesson.ILessonReadersDAO'.", we think
this is the same class, there should be no implicit conversion.

Regards,
Edgar Zavala.
 
Back
Top