Announcement
Collapse
No announcement yet.
C# Referencing other assemblies
Collapse
X
-
Very strange. If I take the script and turn it into a Windows console app (removing the hs.WriteLog calls). It works as expected. Clearly an issue with HS3 and not .NET. I need to see the generated final C# code.
-
Works here also, and curiously I have NO ScriptingReference: in my settings.ini
Z
Leave a comment:
-
That script works here as well.
Code:May-18 1:59:00 PM GetCurrentWeather Current weather conditions retrieved to c:\program files\homeseer hs3\data\CurrentConditions.xml May-18 1:58:59 PM GetCurrentWeather Getting current weather conditions from http://www.weather.gov/xml/current_obs/KFIT.xml May-18 1:58:09 PM Event Running script in background: c:/program files/homeseer hs3/scripts/test.cs
Code:ScriptingReferences=System.Management;System.Management.dll,System.Web;System.web.dll,System.Windows.Forms;System.Windows.Forms.dll,System.Drawing;System.Drawing.dll
Cheers
Al
Leave a comment:
-
Do development on that machine all the time so I doubt it. Like I said, it just stopped working.
Leave a comment:
-
I ran it here and it downloaded the file just fine.
I think it might be something with your .NET installation?
Leave a comment:
-
Originally posted by rmasonjr View PostYeah, not sure what would have changed on the HS side. Were you able to find the generated script? Can you post what you have and the error?
//css_reference System.Net.dll;
using System.Net;
public object Main(object[] Parms) {
const string WeatherURL = "http://www.weather.gov/xml/current_obs/KFIT.xml";
const string ConditonsFile = @"D:\Users\Miles\Documents\Homeseer\Weather Data\CurrentConditions.xml";
hs.WriteLog("GetCurrentWeather", "Getting current weather conditions from " + WeatherURL);
try {
WebClient client = new WebClient();
client.Headers.Add("User-Agent", "HomeSeer/1.0");
client.DownloadFile(WeatherURL, ConditonsFile);
client.Dispose();
hs.WriteLog("GetCurrentWeather", "Current weather conditions retrieved to " + ConditonsFile);
}
catch (Exception ex) {
hs.WriteLog("GetCurrentWeather", "ERROR: Could not retrieve current weather:" + ex.Message);
}
return 0;
}
Here is the error:
Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\UpTime.cs: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
May-18 11:46:00 AM Error Compiling script P:\Program Files (x86)\HomeSeer HS3\scripts\GetWeatherForecast.cs: {interactive}(34,9): error CS0246: The type or namespace name `WebClient' could not be found. Are you missing a using directive or an assembly reference? {interactive}(36,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(36,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(38,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(38,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(40,9): error CS0841: A local variable `client' cannot be used before it is declared {interactive}(40,16): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(9,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used
settings.ini has this:
ScriptingReferences=System.Xml;System.Xml.dll,System.Globali zation;mscorlib.dll,System.Drawing;System.Drawing.dll,System .Net;System.Net.dll
Leave a comment:
-
Yeah, not sure what would have changed on the HS side. Were you able to find the generated script? Can you post what you have and the error?
Leave a comment:
-
It's not the settings.ini. It was working fine until the last day or so.
Leave a comment:
-
It's very likely that your settings.ini has a bad entry. That said, I think that HS generates the code in a Windows temp folder. On my unix platform, the .vb is created in /usr/tmp so I would suspect somewhere in the Windows ether there is a temp folder.
Leave a comment:
-
C# Referencing other assemblies
I'm very frustrated by the lack of info on C# scripting.
1) References to other DLLs. I've added to both ScriptingReferences in the settings.ini file and added the
//css_reference System.Net to the script file (find this lame by the way).
A script which was working just fine, now claims it can't find WebClient. I'm using HS3 3.0.0.280 on Windows.
Is it possible to see what code is wrapped around the script? I know there is some because the line numbers don't line up.
More info would be great.
I know I could do this as a vb script but since I do C# for a living, I'd rather not have to keep switching gears.
Leave a comment: