Question

I have a Windows Phone 7.1 application that references a Windows Phone 7.1 library. That library references a PCL which includes Windows Phone 7 or higher as a target.

At one point, the application attempts to create a new instance of a class from the library which extends a class from the PCL. The PCL class has a protected constructor, so I override it in the library class to make it public. The constructor takes 1 parameter. In the application I create an instance of this one parameter and pass it to the constructor in the library, which has no code of its own, just : base() to the other constructor.

I run the app in the windows phone emulator and it's all going fine. The app loads and I navigate through a few screens.

I hit a breakpoint and step through. I land in the library's constructor fine but then when I try to go one step further, which would be into the PCL's constructor, I just get a TypeLoadException that says "Failure has occurred while loading a type". The stack trace stops at the library constructor and there is no inner exception.

I've also tried the Windows Phone 7.8 emulator. And I've also tried creating the new instance directly in the library class's constructor using a parameterless constructor and just saying : base(new ...) but it all fails the same way.

I have no idea how to figure out what the problem is because I don't know what it might be trying to look for that's unavailable. I see the library and the PCL assemblies listed in the manifest in the project's build directory.

My google fu is coming up dry. Anyone have any ideas where I might be able to continue looking?

Thanks.

Was it helpful?

Solution

I'm a bloody idiot.

So just like it was indicated, there was a problem loading something from the PCL, but it was such an esoteric error .NET wasn't ready for and just barfed without telling me anything.

To troubleshoot it, I commented out the entire body of the constructor which wound up creating instances of several other classes from the PCL and setting them to member variables. This worked.

Then I began uncommenting bits of the constructor until it failed again. Leading me to one class which failed. Passing it null for all objects its constructor took still caused the TypeLoadException so it therefor had to be one of the parameters. I remove all the parameters and lo, it did work. So then I added the parameters back one at a time until it blew up in my face.

It turns out the root of my problem is that despite compiling fine under windows phone 7 and silverlight 4, the PCL was using features windows phone 7 doesn't actually support. Namely, co- and contra-variant generic interfaces. I've had to refactor my PCL so that it can handle invariant generic types and everything proceeds normally.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top