I’m completely rephrasing (more accurately) I am experiencing with losing reference to a referenced class library from a C# Windows service.
Process:
Created a brand new C# .Net v4.0 Windows service.
In that solution I created a new class library that will be called from the service’s OnStart() method, and reference is made in the Windows service to the class library.
I import the RssToolkit project (found here). The RssToolkit project framework is 2.0 (doesn’t matter though), but FYI. Reference is made to the RssToolkit from the class library.
So, we have Windows service –> class library –> RssToolkit.
Windows Service:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using ClassLibraryToExecuteRss;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
Class1.DoSomeWork();
}
protected override void OnStop()
{
}
}
}
Class Library:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RssToolkit.Rss;
namespace ClassLibraryToExecuteRss
{
public static class Class1
{
public static void DoSomeWork()
{
//RssDocument rssDocument = new RssDocument();
//rssDocument = RssDocument.Load(new System.Uri("http://www.somerssurl.com"));
}
}
}
As you can see, lines of code using the RssDocument class are commented out. With these commented out I can compile the solution just fine… but it’s of little use.
Once uncommented, I receive the following compile errors in the service code:
Error 3 The type or namespace name
‘ClassLibraryToExecuteRss’ could not
be found (are you missing a using
directive or an assembly
reference?) C:\Projects\TestBed\TestingServiceWithXLibs\WindowsService1\WindowsService1\Service1.cs 9 7 WindowsService1
…and…
Error 4 The name ‘Class1’ does not
exist in the current
context C:\Projects\TestBed\TestingServiceWithXLibs\WindowsService1\WindowsService1\Service1.cs 22 13 WindowsService1
So what’s going on here? I built a TDD solution that works fine, but when taking the code that calls that class library from my unit tests into the solution, I get this.
I haven’t changed any of the name spaces, and left everything as default.
Incidentally, I did change the target framework of the RssToolkit to 4.0… no change, and I experienced the same issue as I’m using another external library (SubSonic) in my class library.
Can anyone please shed some light on this?
reference both your class library
project and the RssToolkit assembly.