Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to debug System.TypeLoadException for CocosSharp.CocosSharpViewRenderer in Xamarin Forms?

I'm a bit stuck trying to work out what to do next about a very basic error getting started so would really appreciate suggestions.

System.TypeLoadException
Could not load type 'CocosSharp.CocosSharpViewRenderer' from assembly 'CocosSharp.Forms, Version=1.7.0.0, Culture=neutral, PublicKeyToken=null'.

I'm using the new CocosSharp v1.7.0.0-pre1 with Forms in IOS and Android.

I created an app with two tabbed pages, using a Shared project for the app.

The code-behind in one page is:

    public partial class Drawing : ContentPage
    {
        CocosSharpView gameView;

        public Drawing () {
            //InitializeComponent ();
            gameView = new CocosSharpView () {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                DesignResolution = App.screenSize,
                ViewCreated = LoadGame
            };
            Content = gameView;
        }

        void LoadGame(object sender, EventArgs e) {
            var nativeGameView = sender as CocosSharpView;
            if (nativeGameView == null)
                return;
        // more stuff to be added here
        }

The Packages.config file in the IOS project looks like:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CocosSharp" version="1.7.0.0-pre1" targetFramework="xamarinios10" />
  <package id="CocosSharp.Forms" version="1.7.0.0-pre1" targetFramework="xamarinios10" />
  <package id="CocosSharp.PCL.Shared" version="1.6.2.0" targetFramework="xamarinios10" />
  <package id="Xamarin.Forms" version="1.5.1.6471" targetFramework="xamarinios10" />
</packages>

Best Answers

Answers

  • RamiTabbaraRamiTabbara AUMember, Xamarin Team Xamurai

    Hi Andy,

    One thing I noticed is that in your Packages.config there's also a reference to the old CocosSharp.PCL.Shared 1.6.2.0 NuGet which definitely should not be there. So the first thing to do would be to make sure whether both your projects are using the correct references. Probably a clean and rebuild would also be a good idea.

    If you're still having trouble, perhaps try and use either the latest XS and VS project templates and see whether you can get a fresh CocosSharp Forms project up and running. That would help to track down the issue.

  • AndyDentAndyDent AUMember ✭✭

    Thanks @RamiTabbara for your fast response.
    The old CocosSharp.PCL.Shared package was added by Xamarin Studio when I added the other NuGet packages.

    Removing it and doing a clean and rebuild has no effect.

    The new (XS) templates don't help. I had already created a pure IOS Showcase using them and it works fine. Unless I'm missing something, they don't (yet) have a template for Forms-based apps.

    Is there a working, complete example with Forms I can download anywhere?

  • AndyDentAndyDent AUMember ✭✭

    Hmmm, I have to go re-check the templates again because I do NOT have the forms ones (thanks for the screenshot!).

    In Xamarin Studio 5.10 (build 871)
    Interestingly, my top template is called Xamarin.Forms App but yours shows Blank Xamarin.Forms App

    Twice now I have seen it tell me I have an update available for CocosSharp project templates v1.7.0.0-pre1 and that it replaced (exactly the same version string).

    I just tried removing the CocosSharp project templates and adding them again and no change.

    I have one Mac on the Beta channel and the other on Stable.

    My licenses are Indie and Business (for the C# binding work I do for Realm).

    In Xamarin Studio 5.9.8 (build 0)

    it worked - I have the new templates!

    So maybe something about the Add in installation or the project templates clashes with the latest studio!

  • AndyDentAndyDent AUMember ✭✭

    Sigh, Xamarin Studio 5.10 definitely breaks the templates. Stable channel now offers 5.10 (build 871) so I guess it's identical to the one from Beta, being the same build number.

    I just upgraded my stable release and my templates are back to lacking the "Blank Xamarin.Forms App" and _"Cocos Sharp.Forms Game" templates.

    So I uninstalled the templates add-in and re-installed.

    What I think is also significant is, as soon as this add-in is installed it is shown as needing an update, as per the attached screenshot. Note how it says it will be uninstalling and installing the same package!

  • AndyDentAndyDent AUMember ✭✭

    Snap! I was just about to post something to that effect - it's nearly working.

    This morning (GMT+8) I found Xamarin Studio had downloaded an update to the templates, on the stable channel. After a restart, the template works to the extent that the correct options are back and I was able to create a blank CocosSharp.Forms Game

    However it doesn't quite work yet out of the box. The package updates failed when I opened the project:

    Successfully added 'Xamarin.Forms 1.5.1.6471' to CocosSharpTracerXF.iOS.
    
    Adding CocosSharp.Forms...
    Attempting to resolve dependency 'Xamarin.Forms'.
    Attempting to resolve dependency 'CocosSharp'.
    Unable to resolve dependency 'CocosSharp'.
    

    I think the problem is that the template relies on packages which are in the pre-release NuGet so you have to go in and manually select that option and install those packages. I don't know if a template can automate setting the pre-release option (I'm not even sure that is a good idea) but it will catch some people by surprise.

    How about the template description be updated to say REQUIRES PRE-RELEASE NUGET so when people select it in the New Project dialog they would have that reminder?

    Complaint: Please stop releasing updates with identical version numbers I see no reason why it couldn't have been renamed CocosSharp project templates 1.7.0.0-pre2 and that identical numbering may be why it still keeps thinking it is an update that needs installing. I install it, it works, I restart Xamarin Studio and next time I go into Check for Updates it's back again with the same version number.

    But, hey, I'm very happy to have had this resolved and appreciate the support time!

  • AndyDentAndyDent AUMember ✭✭
    edited November 2015

    For anyone following this thread I highly recommend Adam Patridge's blog post on getting started. He walks through the need to manually add packages because of the NuGet Pre-release issue I described above.

Sign In or Register to comment.