Where to exclude design-time code?

I get this error message in the UI tab.

System.BadImageFormatException: Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies cannot be loaded for execution. (0x80131058)
File name: 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
at TableDependency.SqlClient.SqlTableDependency1.CheckIfConnectionStringIsValid() at TableDependency.SqlClient.Base.TableDependency1..ctor(String connectionString, String tableName, String schemaName, IModelToTableMapper1 mapper, IUpdateOfModel1 updateOf, ITableDependencyFilter filter, DmlTriggerType dmlTriggerType, Boolean executeUserPermissionCheck)
at TableDependency.SqlClient.SqlTableDependency1..ctor(String connectionString, String tableName, String schemaName, IModelToTableMapper1 mapper, IUpdateOfModel1 updateOf, ITableDependencyFilter filter, DmlTriggerType notifyOn, Boolean executeUserPermissionCheck, Boolean includeOldValues) at Test.CompanyDatabase2Service..ctor(CompanyDatabase2Context context, NavigationManager navigationManager, IHubContext1 hubContext, IServiceScopeFactory serviceScopeFactory)
at InvokeStub_CompanyDatabase2Service..ctor(Object, Object, IntPtr*)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass7_0.<CreateInitializer>g__Initialize|1(IServiceProvider serviceProvider, IComponent component) at Microsoft.AspNetCore.Components.ComponentFactory.PerformPropertyInjection(IServiceProvider serviceProvider, IComponent instance) at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType) at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame& frame, Int32 parentComponentId) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl) at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
at Radzen.Server.RemoteRenderer.HandleException(Exception exception)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
at Radzen.Server.Router.Render(Type layout, Type component)
at Radzen.Server.Router.OnRouteChanged(Object sender, RouteChangedEventArgs e)
at Radzen.Server.RouterService.Route(Type component, Type defaultLayout)
at Radzen.Server.CircuitHost.AddComponent(Type layout, Type page)
at Radzen.Server.ProjectServer.Render(String fileName, String source)
at Radzen.Server.ProgramController.Render(RenderRequest request)

The app is working fine, it is just the UI-design-time that is having the oh no displayed.

I know i can use:

#if !RADZEN
#endif

To hide code for the design-time builder. But i am not sure where to put it. I get the error on all .razor pages, so my guess is a file that it always look at but i am not sure where.
Can anyone help with this?
I can give you all the code you want, just say what you want.

Is this assembly even compatible with .NET 7? It seems to be released 6 years ago.

The preprocessor code is usually put in the startup - around some AddSingleton, AddService or AddXXX method call.

1 Like

Well the code works fine, but i dont know if there can be any problems using it. I used it for a .NET 6 project where it works good. It also seem to work good with .NET 7 for now. I get the method i created triggered when there is changes to a MS SQL table, and then update the data live in the .razor file using signalr, so so far so good.
And okay i will try to see if i can get it working :blush:

If you inject something that uses this assembly you can surround it with the preprocessor too:

#if !RADZEN
[Inject]
public MyService Service { get; set; }
#endif
1 Like

It worked, so now I can see the design-time, and the real-time data also works. So in some of the next couple of days I will make a tutorial about real-time data using Radzen Blazor Studio and using a RadzenDataGrid to display it.
Thanks for all the help!

2 Likes