views:

438

answers:

4

Does automatic software update causes some of the module property not to work? I am really scratching my head over this function that I have posted here. They are basically the same function that reads image logo from the currently executing assembly. Function named "Get2LogoImageStream" is different from "Get1LogoImageStream" by just Current.ManifestModule.Name vs Current.ManifestModule.ScopeName.

This "Current.ManifestModule.Name " version of the code worked on both Web From app and Windows form app, however right now it only works for Windows App form. But when I changed this code "Current.ManifestModule.Name" with "Current.ManifestModule.ScopeName" and it worked on WEB without any problem. So my questions to fellow C# or VB.NET developers is that does automatic software update causes this kind of issues?

  protected Stream Get1LogoImageStream()
{
    Assembly current = Assembly.GetExecutingAssembly();
    string imageName = "logo.jpg";
    string file = string.Format("{0}.{1}", current.ManifestModule.ScopeName.Replace(".dll", string.Empty), imageName);
    return current.GetManifestResourceStream(file);
}


protected Stream Get2LogoImageStream()
{
    Assembly current = Assembly.GetExecutingAssembly();
    string imageName = "logo.jpg";
    string file = string.Format("{0}.{1}", current.ManifestModule.Name.Replace(".dll", string.Empty), imageName);
    return current.GetManifestResourceStream(file);
}
+1  A: 

Could you tell us how it wasn't working using the original implementation? Any specific exceptions and their messages?

Update: Also, could you do some digging to see what updates were installed recently?

Update: So you're talking about converting assemblies from .NET 2.0 to 3.0/3.5 and not Windows Automatic updates? That's a big difference.

To my knowledge .NET 3.0/3.5 was specifically designed to be fully backwards compatible with .NET 2.0 components, so running a 2.0 assembly on 3.5 shouldn't be an issue. If you're referring to upgrading a .NET 2.0 Project/Solution then I'm not sure.

Another possibility is that there may have been a bug which you relied on in .NET 2.0 that was corrected in .NET 3.5--but that's purely speculation.

STW
Well, basically it was just getting the NULL ref exception; but that is really weird becasue the original code worked with no problems for almost a year now. I am not sure what updates were installed on the deployement server; but My qeustion is mainly is it possible that automatic updates of Version from 2 to 3 or 3.5 has any impact on the existing code+
Shiva
+3  A: 

Since .Name returns just the assembly and .ScopeName returns the full path, it seems likely that something caused your program to need an absolute path to the logo file to operate.

From there, it could be a lot of things, ideas off the top of my head: 1) You had an environment variable storing the path to the image that allowed it to be found.

2) You moved the image or the assembly around, or somehow changed the context the assembly was running in, such that it was searching out the image in the wrong location.

3) Off-chance that some .NET update made it required to use a fully qualified name, but I doubt that one.

Without more details, it would be hard to say.

CodexArcanum
+1  A: 

I would start with using System.IO classes for some of the path manipulation you are doing. The Path class has a nice GetFileNameWithoutExtension method that should (ahem) replace your Replace method call (or maybe even ChangeExtension since that is what you seem to be trying to do anyway).

The main difference I see in regards to Name and ScopeName is that the latter has the full path and the former doesn't. This leads me to think that it is some sort of path issue.

As others have stated, could you post some more details such as errors/exceptions you are getting?

Erich Mirabal
A: 

GetManifestResourceStream() expects the name of your resource which consists of Namespace.ResourceName.Ext.

Since you have to specify the namespace (and not the assembly name) you should include it in your string:

protected Stream Get2LogoImageStream()
{
    Assembly current = Assembly.GetExecutingAssembly();
    string file = "YourNamespace.logo.jpg";
    return current.GetManifestResourceStream(file);
}
chris