none
'type' is defined in an assembly that is not referenced RRS feed

  • Question

  • I've run into this error in the past when compiling my .cs files.  I'm not exactly sure the reason.  I recently read that if you reference an assembly, say assembly A, then all public types referenced by assembly A must also be referenced by you.   Not sure if I worded it correctly.  My question is about the difference between compile time requirements and runtime requirements.

    To test out this issue I created a class called EventSource in namespace Framework.Utility.Instrumentation in assembly Instrumentation.dll.  I created an consumer application called InstrumentationApp.exe which referenced Instrumentation.dll since it made use of the EventSource class.  All compiled fine and ran fine.  Then I created a new class called EventSource in namespace Framework.Instrumentation in assembly EventSource.dll.  I modified the first EventSource class in namespace Framework.Utility.Instrumentation to derive from this new EventSource class.  I reran InstrumentationApp.exe and it ran fine.  When I tried to recompile InstrumentationApp.cs specifying a reference to Instrumentation.dll it complained that Framework.Instrumentation.EventSource is defined in an assembly that is not referenced.  Based on my previous explanation (which may not be correct) regarding compile time reference requirements I can understand why I need a reference to EventSource.dll since I have a public class which is derived from a type in a different assembly so I now need to reference that assembly.  But why does the compiler need this information yet the loaded doesn't need the information?  As I said, InstrumentationApp.exe ran fine after I modified the original EventSource having it derive from the new EventSource.

    Thanks,

    Nick

    Tuesday, November 16, 2010 6:32 PM

Answers

  • Hi Nick,

    Rather confusing question. But let's try anyways:

    "I recently read that if you reference an assembly, say assembly A, then all public types referenced by assembly A must also be referenced by you. Not sure if I worded it correctly". - No. When you reference an assembly, you gain access to that assembly.

    When you created the second EventStore class in EventSource.dll (bad idea to name them identical btw), you also inherited the first eventsource from the second. When you then ran the application, nothing had changed in the .exe. The compiled .exe only changes when you perform a compile.

    So, when you did do a compile, the compiler complained because you were referencing EventSource in eventsource.dll. Everything is working OK in your system and has nothing to do with differences in compile time references versus runtime references.

    Kind regards,
    Tom de Koning

     


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Proposed as answer by Tom de Koning Wednesday, November 17, 2010 5:56 AM
    • Marked as answer by eryang Friday, November 26, 2010 3:52 AM
    Wednesday, November 17, 2010 5:56 AM