I’m trying to develop a simple WP7 database app which uses Linq2SQL to query the database, but today I managed to received an internal compiler error 🙁
A simplified version of my query is below (Results is a class which holds my search results data):
var query =
(
from x in MyTable
join y in MyOtherTable on x.Key equals y.Key
where SqlMethods.Like(x.Field, "%" + searchTerm + "%")
select new Results
{
MyResultField = new Dictionary<MyEnum,string>()
{
{ MyEnum.Value, x.Field },
{ MyEnum.OtherValue, y.Field }
},
...
}
);
However, trying to create a new Dictionary like this results in a raft of compiler errors, even though IntelliSense doesn’t object. I’ve searched around, but I’m not sure how to achieve a similar result without trying to create a Dictionary at this point.
Any ideas for a hopeless newbie?! Many thanks in advance!
Update
Sorry, I forgot to include the compiler errors. Apart from #6, they’re gibberish to me, but if it helps …
# Error 1 Internal Compiler Error: stage 'BEGIN' MyProject
# Error 2 Internal Compiler Error: stage 'EMIT' MyProject
# Error 3 Internal Compiler Error: stage 'COMPILE' MyProject
# Error 4 Internal Compiler Error: stage 'COMPILE' C:\...\ViewModel.cs MyProject
# Error 5 Internal Compiler Error: stage 'COMPILE' symbol '<global namespace>' C:\...\ViewModel.cs MyProject
# Error 6 Internal Compiler Error (0xc0000005 at address 681AB648): likely culprit is 'BIND'.
# An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at which the internal error occurred. Errors such as this can be reported to Microsoft by using the /errorreport option.
# MyProject
# Error 7 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate' C:\...\ViewModel.cs 12 11 MyProject
# Error 8 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject' C:\...\ViewModel.cs 12 11 MyProject
# Error 9 Internal Compiler Error: stage 'COMPILE' symbol 'ChineseClassmate.MyProject.ViewModel' C:\...\ViewModel.cs 12 11 MyProject
# Error 10 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel' C:\...\ViewModel.cs 17 15 MyProject
# Error 11 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 12 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 13 Internal Compiler Error: stage 'COMPILE' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
# Error 14 Internal Compiler Error: stage 'BIND' symbol 'MyProject.ViewModel.MyProjectViewModel.SearchDatabase(string)' C:\...\ViewModel.cs 57 15 MyProject
I don’t believe you can do this. It must be able to translate this call into valid sql and using new objects in there as such I believe will cause a failure as that is not convertible to run all on the db side. You must get your results AND THEN convert to a dictionary (.ToDictionary())