Closed rw-kaber closed 2 years ago
Thanks for reporting. We will look into.
It looks like it is the codeanalyzer/codefixer that rewrites partial controllers (e.g. block controllers) to view components that fails. Do you mind share what your partial controllers look like? It does not need to be all code just the class declarations (including base types?, so something like:
public class MyPartialController : BlockController
Our inheritance tree
SomeBlock
-> ContentBlock
-> BaseBlock
-> EPiServer.Core.BlockData
or
SomeOtherBlock
-> BaseBlock
-> EPiServer.Core.BlockData
PartialContentController
- we don't utilize any
We currently have all Block Controllers setup like:
public class SomeModelController : BlockController<SomeModel>
{
private readonly UrlHelper urlHelper;
private readonly IContentRepository contentRepository;
public SomeModelController(UrlHelper urlHelper, IContentRepository contentRepository)
{
this.urlHelper = urlHelper;
this.contentRepository = contentRepository;
}
public override ActionResult Index(SomeModel currentBlock)
{
return PartialView("/Views/Blocks/SomeModel.cshtml", viewModel);
}
}
We have one controller that looks something like this
public class SomeController : Controller
{
private readonly ICrawlerDetectorHelper crawlerDetectorHelper;
public SomeController(ICrawlerDetectorHelper crawlerDetectorHelper)
{
this.crawlerDetectorHelper = crawlerDetectorHelper;
}
public ActionResult Render(SomeModel model)
{
return PartialView("~/Views/Partials/SomeModelPartial.cshtml", model);
}
}
Ok, that looks normal and is something that the migration tool should handle.
From the call stack it looks like it is a quite simple class replacement that fails. The step will basically look in file https://github.com/episerver/upgrade-assistant-extensions/blob/main/src/EpiSourceUpdater/EpiClassReplacements.classmap for which types that should be mapped to what type. So e.g. your
public class SomeModelController : BlockController<SomeModel>
should be replaced with
public class SomeModelController : BlockComponent<SomeModel>
When looking here
https://github.com/episerver/upgrade-assistant-extensions/blob/main/src/EpiSourceUpdater/EpiClassReplacementsCodeFixProvider.cs#L66
it seems like the code fixer expects the type to map to be a generic type. Could it be that you have a type named BlockController or PartialContentController that is not generic? And use it like
public class NoneGenericController : BlockController
Otherwise what you could do to get more information is to clone this repo and build it in debug and then replace the .dll in the folder you unzipped to with the debug compiled .dll and .pdb. Then you could attach a debugger to the upgrade-assistant process and run it with "break at all exceptions" or put a breakpoint at https://github.com/episerver/upgrade-assistant-extensions/blob/main/src/EpiSourceUpdater/EpiClassReplacementsCodeFixProvider.cs#L66
Hi @jbearfoot, I've managed to catch the exception, however it's being thrown for a perfectly reasonable type.
System.InvalidCastException: 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.QualifiedNameSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax'.'
The block class looks like follows (I've omitted some details, but the constructor declaration is exact match)
public class SomeBlockController : EPiServer.Web.Mvc.BlockController<SomeBlock>
{
private readonly IRequiredClientResourceList requiredClientResourceList;
public SomeBlockController(IRequiredClientResourceList requiredClientResourceList)
{
this.requiredClientResourceList = requiredClientResourceList;
}
public override ActionResult Index(SomeBlock currentContent)
{
if (someCondition)
{
return PartialView("/Views/Blocks/Content/SomeBlockNew.cshtml", currentContent);
}
else
{
return PartialView("/Views/Blocks/Content/SomeBlockOld.cshtml", currentContent);
}
}
}
Hey, also adding to my comment above - all our block use the generic type BlockController<Model>
.
Ah, I would guess that it is because you are using a qualified name like EPiServer.Web.Mvc.BlockController
@jbearfoot It worked, thank you :)
Hi, when running
upgrade-assistant
withEPi.Source.Updater.1.0.27
I get a lot of errors like below, seemingly in a loop, because theupgrade-assistant
is already running for a couple of hours.Could this be connected to blocks without controllers?
EDIT: After stopping and re-running the
upgrade-assistant
a new error emerged: