Unable to cast object of type 'Wisej.Web.Form' to type 'Wisej.Core.IWisejControl' when re-opening WiseJ Project

0
0

Hi,

Any time I re-open a Wisej Project in VS after closing without quitting VS e. g. switching from one solution to another, the Wisej Designer crashes. I always must restart VS. It does not matter which type of Wisej designer object (Page, Window, Desktop) is involved.

Environment:

  • Visual Studio Professional Version 16.7.5
  • Wisej 2.2.14

I never had Wisej 1.x installed or used.

Cheers,

Jens

  • You must to post comments
0
0

The only fix is to make sure that you are not referencing different versions of the assemblies being loaded by the VS designer. Including project assemblies. It’s not a Wisej issue.

VS copies the assemblies loaded by the designer in a shadow directory. When these copies are out of date and cannot be updated or don’t match the references used by other assemblies you see this issue. Sometimes between the same assembly since in .NET you can load multiple identical copies of the same assembly resulting in the same type being loaded more than once and not being able to cast.

We cannot change the way VS loads the assemblies. This problem occurs with all systems (winforms, wpf, asp.net) and all frameworks. Try to delete /bin and /obj, and .vs after closing the designer and VS. Reopen and recompile all. Check the references set to Copy true. Make sure you don’t have multiple versions of the assemblies being designed. Delete the VS shadow temp directories. There are many  sources from Microsoft on where they are located.

Reinstalling VS or Wisej is not related to this. Once you get the hang of it, it should work smoothly. I work daily on dozens of different projects in VS, with multiple versions and many assemblies loaded in the designer without issues. When this happens for me it’s enough to close VS, clean, reopen and it works.

 

  • Jens Daniel
    I debugged VS Designer from another instance of VS, looked at the loaded modules and realized that it loaded each time the solution was re-opened another instance of Wisej.Framework.dll from a different temp folder created below the folder”C:\Users\\AppData\Local\Microsoft\VisualStudio\16.0_0e6d9631\ProjectAssemblies” After closing VS, it loaded only one single instance from the most recent temp folder but started creating temp folders and loading Wisej.Framework.dll additionally each time opening the solution again. While Wisej.Framework.Design.dll has been added to GAC during installation, Wisej.Framework.dll was not. I added it manually to GAC and this fixed the issue for me so far. Should it be in GAC? So there might was an installation glitch that prevented it from being added.
  • Luca (ITG)
    You can add it to the GAC. Our installer doesn’t because otherwise you cannot work with multiple versions, and you have to remember to set Copy Local to true because IIS doesn’t load the assemblies from the GAC and it needs all the deployment in /bin. I work with Wisej 2.1 and 2,2 and several other builds all at the same time (never in the same solution) and also mixing different versions of the designer. When this problem occurs (it’s rare but it does and it always did for winforms, devexpress, wpf) it’s enough to close the designers first, close vs, reopen, clean, rebuild. Sometimes I have to delete .vs because VS becomes too slow to load its own cache, especially for very large projects, in some cases we have 120+ projects in one solution.
  • You must to post comments
0
0

Is there any fix for this problem yet? Seems others have similar issues: Issues opening designer when working in multiple project solutions – Wisej (In my case, I can switch between projects of a solution).

It happens to all Wisej projects even the simplest HelloWorld from template. And yes, I tried all the workarounds that have been posted (except re-installing VS).

I still must always close VS when switching between solutions, even closing+re-opening the same “HelloWorld” crashes.

 

 

 

  • You must to post comments
0
0

This is a common visual studio problem when the same assembly is loaded multiple time. All component libraries using the designer may hit this issue:

https://www.google.com/search?q=visual+studio+a+cannot+be+cast+to+b&rlz=1C1CHBF_enUS870US870&oq=visual+studio+cannot+cast&aqs=chrome.1.69i57j0j69i64.5249j0j1&sourceid=chrome&ie=UTF-8

  • Close all the designer windows
  • Close VS
  • Delete /bin and /obj and /.vs
  • Remove the NuGet package
  • Reopen VS (the design must start closed)
  • Clean, Rebuild
  • Close VS
  • Reopen VS and try the designer

Do this with a new clean project.

Otherwise you have to search for the VS cache and delete it. It’s probably here

C:\Users\%UserName%\AppData\Local\Microsoft\VisualStudio\15.0_6d397e1a\Designer\ShadowCache

15.0_6d397e1a has to be your VS installation instance. There may be more than one.

 

  • Jens Daniel
    Ok I tried this multiple times with new projects, It did not work. Re-opening newly created projects from template which don’t reference nuget packages crashes the designer. Deleting all below ..\AppData\Local\Microsoft\VisualStudio\16.0_0e6d9631\Designer\ShadowCache also didn’t help. This affects only re-opening or switching a solution. If I start VS, open a project and stay there, it is fine. I have VS 2019 (16.7.5) this might be a new issue?
  • You must to post comments
0
0

I also had these errors.

In my case I removed the “WiseJ.Framework” dll from my project and re-add the dll from the local (!) (c => Program Files) folder.

Then it should work.

I got this effect when installing extensions from NuGet and the extensions load the WiseJ.Framework dll from NuGet.

 

  • Jens Daniel
    I tried referencing either file system or nuget. Unfortunately the problem didn’t go away. Even re-opening the same project provokes the effect.
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.