locked
Test framework error: The name 'InitializeComponent' does not exist in the current context RRS feed

  • Question

  • Hello, I am trying to develop a test project for my silverlight app and I think am having trouble getting the test framework installation correct.

    What I've Done:

    As described in Jeff Wilcox's blog (http://www.jeff.wilcox.name/2008/03/silverlight2-unit-testing/#option2) I have copied the 3 framework assemblies into the “%programfiles%\Microsoft SDKs\Silverlight\v2.0\Libraries\Client” directory. I have also added the SilverlightTestProject and SilverlightTestClass zip files into the “%userprofile%\Documents\Visual Studio 2008\Templates\ItemTemplates” directory.

    Errors I'm Getting:

    When I attempt to compile the test project, I am receiving the following 2 errors:

    • In App.xaml's constructor method, the InitializeComponent method gives the error: "The name 'InitializeComponent' does not exist in the current context".
    • In App.xaml's Application_StartUp method's assignment of this.RootVisual = UnitTestSystem.CreateTestPage(this) gives the error: "Cannot implicitly convert type 'System.Windows.DependencyObject' to 'System.Windows.UIElement'. An explicit conversion exists (are you missing a cast?)"
    I can fix the second error with a explicit cast easily enough, however, I am thinking that there is something else that's not right. Any help would be greatly appreciated. Thanks, Vinney

    Friday, March 6, 2009 11:35 AM

Answers

  • Hi,
    Just noticed this thread, sorry for the delay.

    This is likely a version and/or templates mismatch. Please make sure that:

    • You're using Silverlight 2 RTW
    • You're using the latest Silverlight unit test framework binaries
    • Have a reference to System.Core in your Silverlight application (test project) 

    Other details, including the error message you see above, are available at http://www.jeff.wilcox.name/2008/09/unit-testing-rc0-changes/.

    Let me know how it goes. Cheers,

    Sunday, March 15, 2009 10:12 PM

All replies

  • This may help. I am looking at my VS project's XML file and it seems to be having issues with the SilverlightApplication child of the PropertyGroup element and the SilverlightPage child of the ItemGroup element. Is this Normal or does it point to some other issue which could be causing the original issue?
    Friday, March 6, 2009 11:48 AM
  • Ok, I added a UserControl to the project and that gave me a whole new error. Please help.

    Error 1 The "ValidateXaml" task failed unexpectedly. System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified. File name: 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' at System.ModuleHandle.ResolveType(Int32 typeToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount) at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.Module.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, Module decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, RuntimeMethodHandle& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes) at System.Reflection.CustomAttribute.GetCustomAttributes(Assembly assembly, RuntimeType caType) at System.Reflection.Assembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at MS.Internal.Xaml.MS.Impl.XamlSystemBinding.AddPairsFromAssembly(XamlSchemaContext schemaContext, Assembly asm, String uri, List`1 pairs) at MS.Internal.Xaml.MS.Impl.XamlSystemBinding.SearchForXamlNamespace(XamlSchemaContext schemaContext, String uriString, IEnumerable`1 referenceAssemblies) at MS.Internal.Xaml.XamlSchemaContext.GetXamlNamespace(String xmlns, Assembly localAssembly) at MS.Internal.Xaml.XamlSchemaContext.GetXamlNamespace(String xmlns) at MS.MarkupCompiler.ValidationPass.ValidateXaml(String fileName, Assembly[] assemblies, Assembly callingAssembly, TaskLoggingHelper log, Boolean shouldThrow) at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute() at Microsoft.Silverlight.Build.Tasks.ValidateXaml.XamlValidator.Execute() at Microsoft.Silverlight.Build.Tasks.ValidateXaml.Execute() at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. WebServicesTest

    Friday, March 6, 2009 12:14 PM
  •  Hi vinneyk ,

    In App.xaml's constructor method, the InitializeComponent method gives the error: "The name 'InitializeComponent' does not exist in the current context".
     

    Normally, the cause of the error is you renamed or changed the .cs file's namespace, but forget to update the namespace  in xaml file.

     

    Wednesday, March 11, 2009 2:25 AM
  • Hi Amanda and thanks for your response. Unfortunately, this does not help the situation.  The 2 errors specified in the first post appear if a create a brand new SilverlightTest project and attempt to build.

    Wednesday, March 11, 2009 3:56 PM
  • Vinneyk, I've just started with Silverlight myself and just spent a day trying to sort out the same problem and i think I found the solution (hopefully.)  I was scanning through the "option 1" setup in Jeff Wilcox's unit testing article after the "option 2" setup didn't work for me and I found this little bit:

     Replace the RootVisual with a call to UnitTestSystem.CreateTestPage.  The parameter to the method enables the framework’s test engine to reflect on your test assembly.

     It doesn't mention anything about casting the object, but I noticed that there is no parameter being passed if you follow the "option 2" process.  So basically I changed the CreateTestPage line to this:

    this.RootVisual = (UIElement)UnitTestSystem.CreateTestPage(this); 

    Notice at the end how I added "this" as a parameter in addition to adding the cast.  It doesn't specifically say to do this anywhere, but I was at least able to get the AlwaysPass test to execute.  I haven't had time to go any further with it, but maybe that will help you.  Good luck!

     edit: After re-reading the error messages in your first post it looks like you already added "this" as a parameter.

    Sunday, March 15, 2009 10:36 AM
  • Hi,
    Just noticed this thread, sorry for the delay.

    This is likely a version and/or templates mismatch. Please make sure that:

    • You're using Silverlight 2 RTW
    • You're using the latest Silverlight unit test framework binaries
    • Have a reference to System.Core in your Silverlight application (test project) 

    Other details, including the error message you see above, are available at http://www.jeff.wilcox.name/2008/09/unit-testing-rc0-changes/.

    Let me know how it goes. Cheers,

    Sunday, March 15, 2009 10:12 PM
  • Thanks ... that fixed it ... had changed the app.xaml.cs namespace but did not immediately recongize the the spot for that namespace in app.xaml. 

    <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="<put your app.xaml.cs namespance here>"
    >

    Thursday, September 13, 2012 6:54 PM