This project is read-only.

NullReferenceException from AlphaImage.CreateFromResource()

Oct 21, 2010 at 12:20 AM

I am using AlphaImage.CreateFromResource(imageResourceName) to create an AlphaImage object. This was working fine before, and now it is not and I can't figure out why. I am passing a valid resource name. It is a resource that I added using the Resources tab of the project properties. Also in the resources folder the image file is there and the Build Action is set to Embedded Resource. I even used this code to retrieve the available resources, and the one I am using was one of the returned values:

string[] names = Assembly.GetCallingAssembly().GetManifestResourceNames();

Then I was thinking that maybe by the time the AlphaImage.CreateFromResource() method code is running the available resources might be different. So I modified the code to include the above statement and then throw an InvalidOperationException if the passed resource is not an available resource. When I run the program and step through the code with the debugger, the added code is not there anymore and an InvalidOperationException is not thrown and the code keeps running until the NullReferenceException occurs. I searched my projects to see if maybe there was a reference to another version of AlphaMobileControls other than the one with the modified code, but I could not find any.

Any help will be appreciated, thanks in advance!

Oct 21, 2010 at 3:22 AM

I have posted an updated version of this question with my updated progress at

I will post the answer here too when I find it.

Oct 21, 2010 at 6:44 AM

You need to call AlphaImage.CreateFromResource() from the assembly that has the required resource.

The change I made that caused this to stop working was that I moved the class that was calling AlphaImage.CreateFromResource() into a separate library from the one that had the image resource. Therefore Assembly.GetCallingAssembly() which executes from inside AlphaImage.CreateFromResource() is returning the assembly that does not have the resource.