I searched how to make a gadget for windows 7/vista programmatically in c# , at the end I downloaded a visual studio solution called SilverLightGadgetDebugger:
The purpose of the SilverlightGadgetDebugger project is only to act as a debug session starter for the Silverlight gadget. Even though it is a console application project, it produces no output. Instead, whenever the project is started it will invoke the SidebarSandboxStarter.exe file. This application receives the current solution path as a command line parameter. It uses this information to connect to the Visual Studio that has the specified solution opened. The SidebarSandboxStarter will attach the debugger from that instance of Visual Studio to the Windows Sidebar process (sidebar.exe). If the process is not started, it will start it.
I added an Image silverlight control, I'm trying to get the image from this url :
http://lunaf.com/images/moon-phases/lunar_phase_20.jpg
I searched how to get the image , I tried this code :
private void DownloadImage()
{
string ImagePath = "http://lunaf.com/images/moon-phases/lunar_phase_20.jpg";
WebClient client = new WebClient();
client.OpenReadCompleted += client_OpenReadCompleted;
if (ImagePath.IndexOf("http") < 0)
{
string URL = System.Windows.Browser.HtmlPage.Document.DocumentUri.AbsoluteUri;
ImagePath = URL.Substring(0, URL.LastIndexOf('/')) + "/" + ImagePath;
}
client.OpenReadAsync(new Uri(ImagePath, UriKind.RelativeOrAbsolute), ImagePath);
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
try
{
BitmapImage ImageToLoad = new BitmapImage();
ImageToLoad.SetSource(e.Result as Stream);//Here is the exception
Image1.Source = ImageToLoad;
}
catch (Exception ex)
{ }
}
I get an exception , its message (ex.message) :
An exception occurred during the operation, making the result invalid. Check InnerException for exception details.
And the inner exception :
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
how to fix that ??