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

  • Question

  • User42790 posted

    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>
    
    Tuesday, November 17, 2015 8:08 AM

Answers

  • User47368 posted
    The old CocosSharp.PCL.Shared package was added by Xamarin Studio when I added the other NuGet packages.

    Just to make sure, which packages are you adding? In particular, you should only need to install CocosSharp.Forms and it will fetch all the other relevant dependencies for you.

    Also, to cover all bases, keep in mind that you will need at least a Xamarin Indie license to enable Xamarin.Forms.

    If the templates are working for you, then check out the packages.config file to confirm whether indeed it's the case that the old NuGet is no longer there.

    With respect to Forms templates, from the New project window, within the Cross-platform tab, there should be a Forms section where you should see the relevant CocosSharp templates as seen below:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, November 17, 2015 1:49 PM
  • User47368 posted

    Hi Andy,

    There was a slight compatibility issue with XS 5.10 that should now be resolved by re-fetching the project templates (with the same versioning), after which you should be able to see the Forms-specific CocosSharp project templates.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 19, 2015 2:55 AM

All replies

  • User47368 posted

    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.

    Tuesday, November 17, 2015 8:57 AM
  • User42790 posted

    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?

    Tuesday, November 17, 2015 9:54 AM
  • User47368 posted
    The old CocosSharp.PCL.Shared package was added by Xamarin Studio when I added the other NuGet packages.

    Just to make sure, which packages are you adding? In particular, you should only need to install CocosSharp.Forms and it will fetch all the other relevant dependencies for you.

    Also, to cover all bases, keep in mind that you will need at least a Xamarin Indie license to enable Xamarin.Forms.

    If the templates are working for you, then check out the packages.config file to confirm whether indeed it's the case that the old NuGet is no longer there.

    With respect to Forms templates, from the New project window, within the Cross-platform tab, there should be a Forms section where you should see the relevant CocosSharp templates as seen below:

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, November 17, 2015 1:49 PM
  • User42790 posted

    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!

    Tuesday, November 17, 2015 2:17 PM
  • User42790 posted

    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!

    Wednesday, November 18, 2015 2:29 AM
  • User47368 posted

    Hi Andy,

    There was a slight compatibility issue with XS 5.10 that should now be resolved by re-fetching the project templates (with the same versioning), after which you should be able to see the Forms-specific CocosSharp project templates.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 19, 2015 2:55 AM
  • User42790 posted

    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!

    Thursday, November 19, 2015 3:09 AM
  • User42790 posted

    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.

    Sunday, November 22, 2015 6:03 AM